diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 5593636eaf8edc9b5ac8efda8c964c0214e383a9..2d86e9892f99aea2baa4953878726c0ed813585b 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -613,7 +613,7 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p, return error_mark_node; } - if (cxx_dialect < cxx20) + if (cxx_dialect < cxx20 && !explicit_init_p) { auto_diagnostic_group d; tree stripped_init = tree_strip_any_location_wrapper (initializer); diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp63.C b/gcc/testsuite/g++.dg/cpp1z/decomp63.C new file mode 100644 index 0000000000000000000000000000000000000000..50049255efb16c008aa3358dfcef7f9ea007997a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp63.C @@ -0,0 +1,18 @@ +// PR c++/118719 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +int +main () +{ + int a[] = { 42 }; + auto [x] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + // { dg-message "declared here" "" { target c++17_down } .-1 } + [=] () { int b = x; (void) b; }; // { dg-warning "captured structured bindings are a C\\\+\\\+20 extension" "" { target c++17_down } } + [&] () { int b = x; (void) b; }; // { dg-warning "captured structured bindings are a C\\\+\\\+20 extension" "" { target c++17_down } } + [x] () { int b = x; (void) b; }; // { dg-warning "captured structured bindings are a C\\\+\\\+20 extension" "" { target c++17_down } } + [&x] () { int b = x; (void) b; }; // { dg-warning "captured structured bindings are a C\\\+\\\+20 extension" "" { target c++17_down } } + [x = x] () { int b = x; (void) b; }; // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } } + [y = x] () { int b = y; (void) b; }; // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } } + [y = x * 2] () { int b = y; (void) b; }; // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } } +}