| 1 |
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify %s |
| 2 |
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s |
| 3 |
|
| 4 |
namespace Throw { |
| 5 |
|
| 6 |
constexpr int ConditionalThrow(bool t) { |
| 7 |
if (t) |
| 8 |
throw 4; // expected-note {{subexpression not valid in a constant expression}} \ |
| 9 |
// ref-note {{subexpression not valid in a constant expression}} |
| 10 |
|
| 11 |
return 0; |
| 12 |
} |
| 13 |
|
| 14 |
static_assert(ConditionalThrow(false) == 0, ""); |
| 15 |
static_assert(ConditionalThrow(true) == 0, ""); // expected-error {{not an integral constant expression}} \ |
| 16 |
// expected-note {{in call to 'ConditionalThrow(true)'}} \ |
| 17 |
// ref-error {{not an integral constant expression}} \ |
| 18 |
// ref-note {{in call to 'ConditionalThrow(true)'}} |
| 19 |
|
| 20 |
constexpr int Throw() { // expected-error {{never produces a constant expression}} \ |
| 21 |
// ref-error {{never produces a constant expression}} |
| 22 |
throw 5; // expected-note {{subexpression not valid in a constant expression}} \ |
| 23 |
// ref-note {{subexpression not valid in a constant expression}} |
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
constexpr int NoSubExpr() { // ref-error {{never produces a constant expression}} \ |
| 28 |
// expected-error {{never produces a constant expression}} |
| 29 |
throw; // ref-note 2{{subexpression not valid}} \ |
| 30 |
// expected-note 2{{subexpression not valid}} |
| 31 |
return 0; |
| 32 |
} |
| 33 |
static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant expression}} \ |
| 34 |
// ref-note {{in call to}} \ |
| 35 |
// expected-error {{not an integral constant expression}} \ |
| 36 |
// expected-note {{in call to}} |
| 37 |
} |
| 38 |
|
| 39 |
namespace Asm { |
| 40 |
constexpr int ConditionalAsm(bool t) { |
| 41 |
if (t) |
| 42 |
asm(""); // expected-note {{subexpression not valid in a constant expression}} \ |
| 43 |
// ref-note {{subexpression not valid in a constant expression}} |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
static_assert(ConditionalAsm(false) == 0, ""); |
| 48 |
static_assert(ConditionalAsm(true) == 0, ""); // expected-error {{not an integral constant expression}} \ |
| 49 |
// expected-note {{in call to 'ConditionalAsm(true)'}} \ |
| 50 |
// ref-error {{not an integral constant expression}} \ |
| 51 |
// ref-note {{in call to 'ConditionalAsm(true)'}} |
| 52 |
|
| 53 |
|
| 54 |
constexpr int Asm() { // expected-error {{never produces a constant expression}} \ |
| 55 |
// ref-error {{never produces a constant expression}} |
| 56 |
__asm volatile(""); // expected-note {{subexpression not valid in a constant expression}} \ |
| 57 |
// ref-note {{subexpression not valid in a constant expression}} |
| 58 |
return 0; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
namespace Casts { |
| 63 |
constexpr int a = reinterpret_cast<int>(12); // expected-error {{must be initialized by a constant expression}} \ |
| 64 |
// expected-note {{reinterpret_cast is not allowed}} \ |
| 65 |
// ref-error {{must be initialized by a constant expression}} \ |
| 66 |
// ref-note {{reinterpret_cast is not allowed}} |
| 67 |
|
| 68 |
} |