blob: 0e9851aa2ad3a53559478a0c4e048e13fd98fa44 (
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
|
// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c23 -verify=ref,both %s
// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -verify=ref,both %s
typedef typeof(nullptr) nullptr_t;
const _Bool inf1 = (1.0/0.0 == __builtin_inf());
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \
// both-note {{division by zero}}
constexpr _Bool inf3 = __builtin_inf() == __builtin_inf();
/// Used to crash.
struct S {
int x;
char c;
float f;
};
#define DECL_BUFFER(Ty, Name) alignas(Ty) unsigned char Name[sizeof(Ty)]
char bar() {
DECL_BUFFER(struct S, buffer);
((struct S *)buffer)->c = 'a';
return ((struct S *)buffer)->c;
}
static_assert((nullptr_t){} == 0);
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define LITTLE_END 1
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define LITTLE_END 0
#else
# error "huh?"
#endif
typedef unsigned char u8x4_t __attribute__((vector_size(4)));
constexpr u8x4_t arg1 = (u8x4_t)0xCAFEBABE; // okay
#if LITTLE_END
static_assert(arg1[0] == 190);
static_assert(arg1[1] == 186);
static_assert(arg1[2] == 254);
static_assert(arg1[3] == 202);
#else
static_assert(arg1[0] == 202);
static_assert(arg1[1] == 254);
static_assert(arg1[2] == 186);
static_assert(arg1[3] == 190);
#endif
void ghissue109095() {
constexpr char c[] = { 'a' };
constexpr int i = c[1]; // both-error {{constexpr variable 'i' must be initialized by a constant expression}}\
// both-note {{declared here}}
_Static_assert(i == c[0]); // both-error {{static assertion expression is not an integral constant expression}}\
// both-note {{initializer of 'i' is not a constant expression}}
}
|