1 // RUN: %clang_cc1 -std=c++1z -Wno-binding-in-condition -verify %s
6 constexpr explicit operator bool() const {
9 constexpr operator int() const {
15 constexpr int f(X x
) {
20 ok
= {}; // expected-error {{use of undeclared identifier 'ok'}}
21 d
= {}; // expected-error {{use of undeclared identifier 'd'}}
24 static_assert(f({true, 2}) == 3);
25 static_assert(f({false, 2}) == 0);
27 constexpr char g(char const (&x
)[2]) {
33 if (auto [a
, b
] = x
) // expected-error {{an array type is not allowed here}}
37 static_assert(g("x") == 'x');
38 } // namespace CondInIf
40 namespace CondInSwitch
{
41 constexpr int f(int n
) {
42 switch (X s
= {true, n
}; auto [ok
, d
] = s
) {
53 ok
= {}; // expected-error {{use of undeclared identifier 'ok'}}
54 d
= {}; // expected-error {{use of undeclared identifier 'd'}}
55 s
= {}; // expected-error {{use of undeclared identifier 's'}}
58 static_assert(f(0) == 1);
59 static_assert(f(1) == 10);
60 static_assert(f(2) == 80);
61 } // namespace CondInSwitch
63 namespace CondInWhile
{
64 constexpr int f(int n
) {
66 while (auto [ok
, d
] = X
{n
> 1, n
}) {
71 return ok
; // expected-error {{use of undeclared identifier 'ok'}}
74 static_assert(f(0) == 1);
75 static_assert(f(1) == 1);
76 static_assert(f(4) == 24);
77 } // namespace CondInWhile
80 constexpr int f(int n
) {
82 for (X x
= {true, n
}; auto &[ok
, d
] = x
; --d
) {
92 return d
; // expected-error {{use of undeclared identifier 'd'}}
95 static_assert(f(0) == 1);
96 static_assert(f(1) == 1);
97 static_assert(f(2) == 2);
98 static_assert(f(5) == 8);
99 } // namespace CondInFor