60 lines · c
1// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s2// RUN: %clang_cc1 -std=c23 -verify=ref,both %s3// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -fexperimental-new-constant-interpreter -verify=expected,both %s4// RUN: %clang_cc1 -std=c23 -triple=aarch64_be-linux-gnu -verify=ref,both %s5 6 7typedef typeof(nullptr) nullptr_t;8 9const _Bool inf1 = (1.0/0.0 == __builtin_inf());10constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \11 // both-note {{division by zero}}12constexpr _Bool inf3 = __builtin_inf() == __builtin_inf();13 14/// Used to crash.15struct 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 23char bar() {24 DECL_BUFFER(struct S, buffer);25 ((struct S *)buffer)->c = 'a';26 return ((struct S *)buffer)->c;27}28 29static_assert((nullptr_t){} == 0);30 31#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__32# define LITTLE_END 133#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__34# define LITTLE_END 035#else36# error "huh?"37#endif38 39typedef unsigned char u8x4_t __attribute__((vector_size(4)));40constexpr u8x4_t arg1 = (u8x4_t)0xCAFEBABE; // okay41#if LITTLE_END42static_assert(arg1[0] == 190);43static_assert(arg1[1] == 186);44static_assert(arg1[2] == 254);45static_assert(arg1[3] == 202);46#else47static_assert(arg1[0] == 202);48static_assert(arg1[1] == 254);49static_assert(arg1[2] == 186);50static_assert(arg1[3] == 190);51#endif52 53void 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}60