https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114167

            Bug ID: 114167
           Summary: Capturing a auto..., then unpacking it in a lambda
                    taking Ts..., confuses GCC
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

void a(int, int) {}

template<typename... Ts>
void b()
{
    [](auto... ch){
        [ch...](Ts... newvals) {
            (a(ch, newvals), ...);
        }(3,4);
    }(1,2);
}

void c()
{
    b<int,int>();
}


No flags needed. (Needs -std=c++17, but that's the default.)

Expected: Should compile.

Actual:


<source>: In instantiation of 'a<int, int>()::<lambda(auto:1 ...)> [with auto:1
= {int, int}]':
<source>:8:6:   required from 'void a() [with Ts = {int, int}]'
<source>:13:15:   required from here
<source>:6:19: error: 'newvals#0' is not captured
    6 |             ((ch, newvals), ...);
      |                   ^~~~~~~
<source>:5:9: note: the lambda has no capture-default
    5 |         [ch...](Ts... newvals) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
    6 |             ((ch, newvals), ...);
      |             ~~~~~~~~~~~~~~~~~~~~~
    7 |         }(3,4);
      |         ~
<source>:5:19: note: 'int newvals#0' declared here
    5 |         [ch...](Ts... newvals) {
      |                 ~~^~~~~~~~~~~
Compiler returned: 1


I'm not 100% sure if that is valid C++, but Clang accepts it, and the error
message somehow manages to ask to capture newvals before it's declared.

https://godbolt.org/z/G8Kh9rvYc

Reply via email to