Structured bindings do not work with `environment::key_value_pair[_view]`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- operating-systems
Research direction
Start with boost/process/environment.hpp and the key_value_pair_view and tuple_size definitions referenced in boost/process/v2/environment.hpp. Reproduce the supplied bug.cpp with GCC and Clang; done means both const and non-const structured-binding examples compile successfully.
Written by the indexing model from the issue text.
Description
Structured bindings do not work with environment::key_value_pair and environment::key_value_pair_view. For example, the following code does not compile when using GCC 15.2.1 or Clang 21.1.6 on Linux:
#include <iostream>
#include <boost/process/environment.hpp>
int main() {
for (const auto [name, value] : boost::process::environment::current())
std::cout << name << '=' << value << '\n';
return 0;
}
Compiler output
$ g++ bug.cpp -lboost_process
bug.cpp: In function ‘int main()’:
bug.cpp:5:21: error: cannot decompose inaccessible member ‘boost::process::v2::environment::key_value_pair_view::value_’ of ‘const boost::process::v2::environment::key_value_pair_view’
5 | for (const auto [name, value] : boost::process::environment::current())
| ^~~~~~~~~~~~~
In file included from /usr/include/boost/process/environment.hpp:1,
from bug.cpp:2:
/usr/include/boost/process/v2/environment.hpp:435:20: note: declared private here
435 | string_view_type value_;
| ^~~~~~
$ clang bug.cpp -lboost_process
bug.cpp:5:21: error: type 'const key_value_pair_view' decomposes into 1 element, but 2 names were
provided
5 | for (const auto [name, value] : boost::process::environment::current())
| ^
/usr/include/boost/process/v2/environment.hpp:1377:14: note: selected 'begin' function with
iterator type 'iterator'
1377 | iterator begin() const {return iterator(handle_.get());}
| ^
1 error generated.
Interestingly, if const auto is replaced with just auto, GCC compiles the code without any warnings, while Clang still does not compile it but produces a different error message, that seems to explain the actual cause:
bug.cpp:5:15: error: 'value' is a private member of 'std::integral_constant<unsigned long, 2>'
5 | for (auto [name, value] : boost::process::environment::current())
| ^
/usr/include/boost/process/v2/environment.hpp:1280:82: note: constrained by implicitly private
inheritance here
1280 | class tuple_size<BOOST_PROCESS_V2_NAMESPACE::environment::key_value_pair_view> : integral_constant<std::size_t, 2u> {};
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15/type_traits:94:28: note:
member is declared here
94 | static constexpr _Tp value = __v;
| ^
1 error generated.
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/process
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in boostorg/process
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·