`<complex>`: Structured binding for `complex` is accidentally enabled before C++26, in a C++26-incompatible way
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
When attempting to implement WG21-P2819R2 "Add The Tuple Protocol To complex", I found that the following thing is accepted by MSVC STL (Godbolt link).
#include <complex>
int main() {
auto [xy] = std::complex<double>{};
}
Currently, MSVC STL's complex satisfies the conditions in [dcl.struct.bind]/8 - it has only one data member of type value_type[2] which is public and inherited from its base class.
Since C++26, the aforementioned example will certainly stop working. Do we want to reject it in old modes by making something private? Given complex doesn't seem able to be passed or returned in registers, perhaps such change is ABI-compatible.
Contributor guide
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.
Research direction
Start with the structured-binding example using and reproduce its acceptance in pre-C++26 modes via the linked Godbolt case. Read [dcl.struct.bind]/8 alongside WG21-P2819R2, then determine whether the compatibility issue requires rejecting the existing form and what ABI implications that has. Done means the expected behavior and an appropriate change or decision are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100