[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / test / AST / ByteCode / invalid.cpp
blob2a6c2d13e846738613f2d2bbc58ba1607c9db8af
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
4 namespace Throw {
6 constexpr int ConditionalThrow(bool t) {
7 if (t)
8 throw 4; // both-note {{subexpression not valid in a constant expression}}
10 return 0;
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}}
19 return 0;
22 constexpr int NoSubExpr() { // both-error {{never produces a constant expression}}
23 throw; // both-note 2{{subexpression not valid}}
24 return 0;
26 static_assert(NoSubExpr() == 0, ""); // both-error {{not an integral constant expression}} \
27 // both-note {{in call to}}
30 namespace Asm {
31 constexpr int ConditionalAsm(bool t) {
32 if (t)
33 asm(""); // both-note {{subexpression not valid in a constant expression}}
35 return 0;
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}}
44 return 0;
48 namespace Casts {
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}}
52 void func() {
53 struct B {};
54 B b;
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");