blob: c41c82292e8de43d1d551730487409d1a873c1c4 [file] [log] [blame]
Zhihao Yuanc81f4532017-12-07 07:03:15 +00001// RUN: %clang_cc1 -std=c++1z %s -verify
2
3struct Na {
4 bool flag;
5 float data;
6};
7
8struct Rst {
9 bool flag;
10 float data;
11 explicit operator bool() const {
12 return flag;
13 }
14};
15
16Rst f();
17Na g();
18
19namespace CondInIf {
20void 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
28namespace CondInWhile {
29void 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
37namespace CondInFor {
38void 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
46struct IntegerLike {
47 bool flag;
48 float data;
49 operator int() const {
50 return int(data);
51 }
52};
53
54namespace CondInSwitch {
55void 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