1 // RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify=expected,both %s
2 // RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref,both %s
6 constexpr int ConditionalThrow(bool t
) {
8 throw 4; // both-note {{subexpression not valid in a constant expression}}
13 static_assert(ConditionalThrow(false) == 0, "");
14 static_assert(ConditionalThrow(true) == 0, ""); // both-error {{not an integral constant expression}} \
15 // both-note {{in call to 'ConditionalThrow(true)'}}
17 constexpr int Throw() { // both-error {{never produces a constant expression}}
18 throw 5; // both-note {{subexpression not valid in a constant expression}}
22 constexpr int NoSubExpr() { // both-error {{never produces a constant expression}}
23 throw; // both-note 2{{subexpression not valid}}
26 static_assert(NoSubExpr() == 0, ""); // both-error {{not an integral constant expression}} \
27 // both-note {{in call to}}
31 constexpr int ConditionalAsm(bool t
) {
33 asm(""); // both-note {{subexpression not valid in a constant expression}}
37 static_assert(ConditionalAsm(false) == 0, "");
38 static_assert(ConditionalAsm(true) == 0, ""); // both-error {{not an integral constant expression}} \
39 // both-note {{in call to 'ConditionalAsm(true)'}}
42 constexpr int Asm() { // both-error {{never produces a constant expression}}
43 __asm
volatile(""); // both-note {{subexpression not valid in a constant expression}}
49 constexpr int a
= reinterpret_cast<int>(12); // both-error {{must be initialized by a constant expression}} \
50 // both-note {{reinterpret_cast is not allowed}}
55 (void)*reinterpret_cast<void*>(&b
); // both-error {{indirection not permitted on operand of type 'void *'}}
58 /// Just make sure this doesn't crash.
59 float PR9558
= reinterpret_cast<const float&>("asd");