1- // RUN: %clang_cc1 -std=c++1z -Wno-c++26-extensions -verify %s
2- // RUN: %clang_cc1 -std=c++1z -Wno-c++26-extensions -verify %s -fexperimental-new-constant-interpreter
1+ // RUN: %clang_cc1 -std=c++17 -Wno-c++26-extensions -verify %s
2+ // RUN: %clang_cc1 -std=c++17 -Wno-c++26-extensions -verify %s -fexperimental-new-constant-interpreter
3+ // RUN: %clang_cc1 -std=c++2c -Wpre-c++26-compat -verify=cxx26,expected %s
4+ // RUN: %clang_cc1 -std=c++2c -Wpre-c++26-compat -verify=cxx26,expected %s -fexperimental-new-constant-interpreter
35
46struct X {
57 bool flag;
@@ -14,7 +16,7 @@ struct X {
1416
1517namespace CondInIf {
1618constexpr int f (X x) {
17- if (auto [ok, d] = x)
19+ if (auto [ok, d] = x) // cxx26-warning {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
1820 return d + int (ok);
1921 else
2022 return d * int (ok);
@@ -26,12 +28,13 @@ static_assert(f({true, 2}) == 3);
2628static_assert (f({false , 2 }) == 0 );
2729
2830constexpr char g (char const (&x)[2]) {
29- if (auto &[a, b] = x)
31+ if (auto &[a, b] = x) // cxx26-warning {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
3032 return a;
3133 else
3234 return b;
3335
34- if (auto [a, b] = x) // expected-error {{an array type is not allowed here}}
36+ if (auto [a, b] = x) // expected-error {{an array type is not allowed here}} \
37+ // cxx26-warning {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
3538 ;
3639}
3740
@@ -41,6 +44,7 @@ static_assert(g("x") == 'x');
4144namespace CondInSwitch {
4245constexpr int f (int n) {
4346 switch (X s = {true , n}; auto [ok, d] = s) {
47+ // cxx26-warning@-1 {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
4448 s = {};
4549 case 0 :
4650 return int (ok);
@@ -65,6 +69,7 @@ namespace CondInWhile {
6569constexpr int f (int n) {
6670 int m = 1 ;
6771 while (auto [ok, d] = X{n > 1 , n}) {
72+ // cxx26-warning@-1 {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
6873 m *= d;
6974 --n;
7075 }
@@ -81,6 +86,7 @@ namespace CondInFor {
8186constexpr int f (int n) {
8287 int a = 1 , b = 1 ;
8388 for (X x = {true , n}; auto &[ok, d] = x; --d) {
89+ // cxx26-warning@-1 {{structured binding declaration in a condition is incompatible with C++ standards before C++2c}}
8490 if (d < 2 )
8591 ok = false ;
8692 else {
0 commit comments