| 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 |
| 3 |
|
| 4 |
namespace ConstEval { |
| 5 |
constexpr int f() { |
| 6 |
int i = 0; |
| 7 |
if consteval { |
| 8 |
i = 1; |
| 9 |
} |
| 10 |
return i; |
| 11 |
} |
| 12 |
static_assert(f() == 1, ""); |
| 13 |
|
| 14 |
constexpr int f2() { |
| 15 |
int i = 0; |
| 16 |
if !consteval { |
| 17 |
i = 12; |
| 18 |
if consteval { |
| 19 |
i = i + 1; |
| 20 |
} |
| 21 |
} |
| 22 |
return i; |
| 23 |
} |
| 24 |
static_assert(f2() == 0, ""); |
| 25 |
}; |
| 26 |
|
| 27 |
namespace InitDecl { |
| 28 |
constexpr bool f() { |
| 29 |
if (int i = 5; i != 10) { |
| 30 |
return true; |
| 31 |
} |
| 32 |
return false; |
| 33 |
} |
| 34 |
static_assert(f(), ""); |
| 35 |
|
| 36 |
constexpr bool f2() { |
| 37 |
if (bool b = false; b) { |
| 38 |
return true; |
| 39 |
} |
| 40 |
return false; |
| 41 |
} |
| 42 |
static_assert(!f2(), ""); |
| 43 |
|
| 44 |
|
| 45 |
constexpr int attrs() { |
| 46 |
if (1) [[likely]] {} |
| 47 |
return 1; |
| 48 |
} |
| 49 |
static_assert(attrs() == 1, ""); |
| 50 |
}; |
| 51 |
|
| 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}} |
| 58 |
; |
| 59 |
} |
| 60 |
static_assert(g("x") == 'x'); |