microsoft / microsoft/STL

`<complex>`: Structured binding for `complex` is accidentally enabled before C++26, in a C++26-incompatible way

Open
#5,913 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.