| 1 |
// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify -Wno-c23-extensions |
| 2 |
// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify -fexperimental-new-constant-interpreter -Wno-c23-extensions |
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
constexpr int value(int a, int b) { |
| 6 |
return a + b; |
| 7 |
} |
| 8 |
|
| 9 |
constexpr int func_call() { |
| 10 |
return value( |
| 11 |
#embed <jk.txt> |
| 12 |
); |
| 13 |
} |
| 14 |
|
| 15 |
constexpr int init_list_expr() { |
| 16 |
int vals[] = { |
| 17 |
#embed <jk.txt> |
| 18 |
}; |
| 19 |
return value(vals[0], vals[1]); |
| 20 |
} |
| 21 |
|
| 22 |
template <int N, int M> |
| 23 |
struct Hurr { |
| 24 |
static constexpr int V1 = N; |
| 25 |
static constexpr int V2 = M; |
| 26 |
}; |
| 27 |
|
| 28 |
constexpr int template_args() { |
| 29 |
Hurr< |
| 30 |
#embed <jk.txt> |
| 31 |
> H; |
| 32 |
return value(H.V1, H.V2); |
| 33 |
} |
| 34 |
|
| 35 |
constexpr int ExpectedValue = 'j' + 'k'; |
| 36 |
static_assert(func_call() == ExpectedValue); |
| 37 |
static_assert(init_list_expr() == ExpectedValue); |
| 38 |
static_assert(template_args() == ExpectedValue); |
| 39 |
|
| 40 |
static_assert( |
| 41 |
#embed <jk.txt> limit(1) suffix(== 'j') |
| 42 |
); |
| 43 |
|
| 44 |
int array[ |
| 45 |
#embed <jk.txt> limit(1) |
| 46 |
]; |
| 47 |
static_assert(sizeof(array) / sizeof(int) == 'j'); |
| 48 |
|
| 49 |
constexpr int comma_expr = ( |
| 50 |
#embed <jk.txt> |
| 51 |
); |
| 52 |
static_assert(comma_expr == 'k'); |
| 53 |
|
| 54 |
constexpr int comma_expr_init_list{ ( |
| 55 |
#embed <jk.txt> limit(1) |
| 56 |
) }; |
| 57 |
static_assert(comma_expr_init_list == 'j'); |
| 58 |
|
| 59 |
constexpr int paren_init( |
| 60 |
#embed <jk.txt> limit(1) |
| 61 |
); |
| 62 |
static_assert(paren_init == 'j'); |
| 63 |
|
| 64 |
struct S { |
| 65 |
const char buffer[2] = { |
| 66 |
#embed "jk.txt" |
| 67 |
}; |
| 68 |
}; |
| 69 |
|
| 70 |
constexpr struct S s; |
| 71 |
static_assert(s.buffer[1] == 'k'); |
| 72 |
|
| 73 |
struct S1 { |
| 74 |
int x, y; |
| 75 |
}; |
| 76 |
|
| 77 |
struct T { |
| 78 |
int x, y; |
| 79 |
struct S1 s; |
| 80 |
}; |
| 81 |
|
| 82 |
constexpr struct T t[] = { |
| 83 |
#embed <numbers.txt> |
| 84 |
}; |
| 85 |
static_assert(t[0].s.x == '2'); |
| 86 |
|
| 87 |
constexpr int func(int i, int) { return i; } |
| 88 |
static_assert( |
| 89 |
func( |
| 90 |
#embed <jk.txt> |
| 91 |
) == 'j'); |
| 92 |
|
| 93 |
template <int N> |
| 94 |
struct ST {}; |
| 95 |
|
| 96 |
ST< |
| 97 |
#embed <jk.txt> limit(1) |
| 98 |
> st; |
| 99 |
|
| 100 |
struct HasCharArray { unsigned char h[10]; }; |
| 101 |
struct Wrapper { int a; struct HasCharArray d; }; |
| 102 |
constexpr struct Wrapper W = { |
| 103 |
#embed "numbers.txt" |
| 104 |
}; |
| 105 |
|
| 106 |
static_assert(W.d.h[2] == '3'); |