https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85889
Giuseppe D'Angelo <dangelog at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dangelog at gmail dot com --- Comment #8 from Giuseppe D'Angelo <dangelog at gmail dot com> --- Hi, GCC 15 seems to be emitting the C++20 compatibility warning even when a structured binding is used in an init-capture's initializer, not just in a simple-capture: https://gcc.godbolt.org/z/TnzWs8xne int main() { int a[] = { 42 }; auto [x] = a; [x](){}; // 1 [x=x](){}; // 2 [test = x](){}; // 3 [test = x * 2](){}; // 4 } > <source>: In function 'int main()': > <source>:7:6: warning: captured structured bindings are a C++20 extension > [-Wc++20-extensions] > 7 | [x](){}; // 1 > | ^ > <source>:5:11: note: declared here > 5 | auto [x] = a; > | ^ > <source>:8:8: warning: captured structured bindings are a C++20 extension > [-Wc++20-extensions] > 8 | [x=x](){}; // 2 > | ^ > <source>:5:11: note: declared here > 5 | auto [x] = a; > | ^ > <source>:9:13: warning: captured structured bindings are a C++20 extension > [-Wc++20-extensions] > 9 | [test = x](){}; // 3 > | ^ > <source>:5:11: note: declared here > 5 | auto [x] = a; > | ^ > Compiler returned: 0 (1) is OK, but (2) and (3) shouldn't warn. (4) doesn't warn. AFAICS, the code should be fine, as init-captures don't impose anything here? * In C++17 (N4659), [expr.prim.lambda.capture]/6: "An init-capture behaves as if it declares and explicitly captures a variable of the form “auto init-capture ;” whose declarative region is the lambda-expression's compound-statement" (https://timsong-cpp.github.io/cppwp/n4659/expr.prim.lambda.capture#6) * The current draft says: "An init-capture without ellipsis behaves as if it declares and explicitly captures a variable of the form “auto init-capture ;”" (https://eel.is/c++draft/expr.prim.lambda.capture#6) For comparison, Clang doesn't warn.