1 // RUN: %clang_cc1 -std=c++1z %s -verify
4 template<typename
> struct tuple_size
;
5 template<int, typename
> struct tuple_element
;
9 template<int> int get() { return 0; }
10 operator bool() { return true; }
14 template<> struct tuple_size
<Get
> { static constexpr int value
= 1; };
15 template<> struct tuple_element
<0, Get
> { using type
= int; };
26 explicit operator bool() const {
36 if (auto [ok
, d
] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
38 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'}}
40 if (auto [value
] = Get()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
43 } // namespace CondInIf
45 namespace CondInWhile
{
47 while (auto [ok
, d
] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
49 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'}}
51 while (auto [value
] = Get()) // expected-warning{{ISO C++17 does not permit structured binding declaration in a condition}}
54 } // namespace CondInWhile
58 for (; auto [ok
, d
] = f();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
60 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'}}
62 for (; auto [value
] = Get();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
65 } // namespace CondInFor
70 operator int() const {
75 namespace CondInSwitch
{
76 int h(IntegerLike x
) {
77 switch (auto [ok
, d
] = x
) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
79 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)}}
81 switch (auto [value
] = Get()) {// expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
82 // expected-warning@-1{{switch condition has boolean value}}
87 } // namespace CondInSwitch