| 1 |
// RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify -fcxx-exceptions |
| 2 |
// RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify -fexperimental-new-constant-interpreter -fcxx-exceptions |
| 3 |
|
| 4 |
namespace GH139818{ |
| 5 |
struct A { |
| 6 |
constexpr ~A() { ref = false; } |
| 7 |
constexpr operator bool() { |
| 8 |
return b; |
| 9 |
} |
| 10 |
bool b; |
| 11 |
bool& ref; |
| 12 |
}; |
| 13 |
|
| 14 |
constexpr bool f1() { |
| 15 |
bool ret = true; |
| 16 |
for (bool b = false; A x{b, ret}; b = true) {} |
| 17 |
return ret; |
| 18 |
} |
| 19 |
|
| 20 |
static_assert(!f1()); |
| 21 |
|
| 22 |
struct Y { |
| 23 |
constexpr ~Y() noexcept(false) { throw "oops"; } // expected-note {{subexpression not valid in a constant expression}} |
| 24 |
|
| 25 |
constexpr operator bool() { |
| 26 |
return b; |
| 27 |
} |
| 28 |
bool b; |
| 29 |
}; |
| 30 |
constexpr bool f2() { |
| 31 |
for (bool b = false; Y x = {b}; b = true) {} // expected-note {{in call to 'x.~Y()'}} |
| 32 |
return true; |
| 33 |
} |
| 34 |
static_assert(f2()); // expected-error {{static assertion expression is not an integral constant expression}} |
| 35 |
// expected-note@-1 {{in call to 'f2()'}} |
| 36 |
}; |