Bug 91847 - init-capture pack of references requires ... on wrong side
Summary: init-capture pack of references requires ... on wrong side
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2019-09-20 23:26 UTC by Barry Revzin
Modified: 2020-02-24 14:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-09-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2019-09-20 23:26:03 UTC
gcc implements the letter of the standard and allows this:

template <typename... T>
void foo(T&... ts) {
    [...&us=ts]{};
}

While that is valid per the latest working draft, and is the wording specified in P0780R2, the direction we really want to go in is to put the ... on the other side of the &. That is, the declaration of 'us' should look the same as the declaration of 'ts'. This is CWG 2378.

In other words, the correct syntax should be:

template <typename... T>
void foo(T&... ts) {
    [&...us=ts]{};
}

clang implements the CWG 2378 rule, this issue should hopefully be resolved by the time C++20 ships.
Comment 1 Marek Polacek 2019-09-21 00:59:59 UTC
Confirmed.
Comment 2 Barry Revzin 2020-02-15 17:28:43 UTC
In the Prague meeting, this paper (https://brevzin.github.io/cpp_proposals/2095_lambda_pack_cwg/p2095r0.html) was adopted into what will become the C++20 standard, which moves the & in the grammar to the left side of the ellipses. 

So now I can say officially, [&...us=ts]{} is the correct spelling.
Comment 3 Marek Polacek 2020-02-24 14:33:04 UTC
Actually this was just fixed:
r10-6813-g32b8f5df9f05426c82c6de1acaf9ca4aec68039d