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