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
6 constexpr int ConditionalThrow(bool t
) {
8 throw 4; // expected-note {{subexpression not valid in a constant expression}} \
9 // ref-note {{subexpression not valid in a constant expression}}
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)'}}
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}}
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}}
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}}
40 constexpr int ConditionalAsm(bool t
) {
42 asm(""); // expected-note {{subexpression not valid in a constant expression}} \
43 // ref-note {{subexpression not valid in a constant expression}}
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)'}}
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}}
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}}