1 // RUN: %clang_cc1 -std=c++1z %s -verify 2 3 struct Na { 4 bool flag; 5 float data; 6 }; 7 8 struct Rst { 9 bool flag; 10 float data; 11 explicit operator bool() const { 12 return flag; 13 } 14 }; 15 16 Rst f(); 17 Na g(); 18 19 namespace CondInIf { 20 void h() { 21 if (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} 22 ; 23 if (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}} 24 ; 25 } 26 } // namespace CondInIf 27 28 namespace CondInWhile { 29 void h() { 30 while (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} 31 ; 32 while (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}} 33 ; 34 } 35 } // namespace CondInWhile 36 37 namespace CondInFor { 38 void h() { 39 for (; auto [ok, d] = f();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} 40 ; 41 for (; auto [ok, d] = g();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}} 42 ; 43 } 44 } // namespace CondInFor 45 46 struct IntegerLike { 47 bool flag; 48 float data; 49 operator int() const { 50 return int(data); 51 } 52 }; 53 54 namespace CondInSwitch { 55 void h(IntegerLike x) { 56 switch (auto [ok, d] = x) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} 57 ; 58 switch (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{statement requires expression of integer type ('Na' invalid)}} 59 ; 60 } 61 } // namespace CondInSwitch 62