| 1 |
// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s |
| 2 |
// RUN: %clang_cc1 -std=c23 -verify=ref,both %s |
| 3 |
// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -fexperimental-new-constant-interpreter -verify=expected,both %s |
| 4 |
// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -verify=ref,both %s |
| 5 |
|
| 6 |
|
| 7 |
typedef typeof(nullptr) nullptr_t; |
| 8 |
|
| 9 |
const _Bool inf1 = (1.0/0.0 == __builtin_inf()); |
| 10 |
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \ |
| 11 |
// both-note {{division by zero}} |
| 12 |
constexpr _Bool inf3 = __builtin_inf() == __builtin_inf(); |
| 13 |
|
| 14 |
/// Used to crash. |
| 15 |
struct S { |
| 16 |
int x; |
| 17 |
char c; |
| 18 |
float f; |
| 19 |
}; |
| 20 |
|
| 21 |
#define DECL_BUFFER(Ty, Name) alignas(Ty) unsigned char Name[sizeof(Ty)] |
| 22 |
|
| 23 |
char bar() { |
| 24 |
DECL_BUFFER(struct S, buffer); |
| 25 |
((struct S *)buffer)->c = 'a'; |
| 26 |
return ((struct S *)buffer)->c; |
| 27 |
} |
| 28 |
|
| 29 |
static_assert((nullptr_t){} == 0); |
| 30 |
|
| 31 |
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 32 |
# define LITTLE_END 1 |
| 33 |
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 34 |
# define LITTLE_END 0 |
| 35 |
#else |
| 36 |
# error "huh?" |
| 37 |
#endif |
| 38 |
|
| 39 |
typedef unsigned char u8x4_t __attribute__((vector_size(4))); |
| 40 |
constexpr u8x4_t arg1 = (u8x4_t)0xCAFEBABE; // okay |
| 41 |
#if LITTLE_END |
| 42 |
static_assert(arg1[0] == 190); |
| 43 |
static_assert(arg1[1] == 186); |
| 44 |
static_assert(arg1[2] == 254); |
| 45 |
static_assert(arg1[3] == 202); |
| 46 |
#else |
| 47 |
static_assert(arg1[0] == 202); |
| 48 |
static_assert(arg1[1] == 254); |
| 49 |
static_assert(arg1[2] == 186); |
| 50 |
static_assert(arg1[3] == 190); |
| 51 |
#endif |
| 52 |
|
| 53 |
void ghissue109095() { |
| 54 |
constexpr char c[] = { 'a' }; |
| 55 |
constexpr int i = c[1]; // both-error {{constexpr variable 'i' must be initialized by a constant expression}}\ |
| 56 |
// both-note {{declared here}} |
| 57 |
_Static_assert(i == c[0]); // both-error {{static assertion expression is not an integral constant expression}}\ |
| 58 |
// both-note {{initializer of 'i' is not a constant expression}} |
| 59 |
} |