[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / test / AST / ByteCode / if.cpp
blob540cb76fbaac3c2cc8a18d5bd6a76c7cef864cd0
1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fexperimental-new-constant-interpreter %s -verify=expected,both
2 // RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify=ref,both
4 namespace ConstEval {
5 constexpr int f() {
6 int i = 0;
7 if consteval {
8 i = 1;
10 return i;
12 static_assert(f() == 1, "");
14 constexpr int f2() {
15 int i = 0;
16 if !consteval {
17 i = 12;
18 if consteval {
19 i = i + 1;
22 return i;
24 static_assert(f2() == 0, "");
27 namespace InitDecl {
28 constexpr bool f() {
29 if (int i = 5; i != 10) {
30 return true;
32 return false;
34 static_assert(f(), "");
36 constexpr bool f2() {
37 if (bool b = false; b) {
38 return true;
40 return false;
42 static_assert(!f2(), "");
45 constexpr int attrs() {
46 if (1) [[likely]] {}
47 return 1;
49 static_assert(attrs() == 1, "");
52 /// The faulty if statement creates a RecoveryExpr with contains-errors,
53 /// but the execution will never reach that.
54 constexpr char g(char const (&x)[2]) {
55 return 'x';
56 if (auto [a, b] = x) // both-error {{an array type is not allowed here}} \
57 // both-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
60 static_assert(g("x") == 'x');
62 namespace IfScope {
63 struct Inc {
64 int &a;
65 constexpr Inc(int &a) : a(a) {}
66 constexpr ~Inc() { ++a; }
69 constexpr int foo() {
70 int a= 0;
71 int b = 12;
72 if (Inc{a}; true) {
73 b += a;
75 return b;
77 static_assert(foo() == 13, "");