brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 4ad2fff Raw
89 lines · c
1// RUN: %clang_cc1 -std=c23 -verify -triple x86_64 -pedantic -Wno-conversion -Wno-constant-conversion %s2// RUN: %clang_cc1 -std=c23 -verify -triple x86_64 -pedantic -Wno-conversion -Wno-constant-conversion -fexperimental-new-constant-interpreter %s3 4/* WG14 N3018: Full5 * The constexpr specifier for object definitions6 */7 8#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)9#define UINT_MAX  (__INT_MAX__  *2U +1U)10 11void Example0() {12  constexpr unsigned int minusOne    = -1;13  // expected-error@-1 {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned int'}}14  constexpr unsigned int uint_max    = -1U;15  constexpr double onethird          = 1.0/3.0;16  constexpr double onethirdtrunc     = (double)(1.0/3.0);17 18  constexpr char string[] = { "\xFF", };19  constexpr unsigned char ucstring[] = { "\xFF", };20  // expected-error@-1 {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned char'}}21  constexpr char string1[] = { -1, 0, };22  constexpr unsigned char ucstring1[] = { -1, 0, };23  // expected-error@-1 {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned char'}}24 25  // TODO: Make sure these work correctly once char8_t and _Decimal are supported26  // constexpr char8_t u8string[] = { 255, 0, }; // ok27  // constexpr char8_t u8string[]       = { u8"\xFF", };     // ok28  // constexpr _Decimal32 small         = DEC64_TRUE_MIN * 0;// constraint violation29}30 31void Example1() {32  constexpr int K = 47;33  enum {34      A = K,35  };36  constexpr int L = K;37  static int b    = K + 1;38  int array[K];39  _Static_assert(K == 47);40}41 42constexpr int K = 47;43static const int b = K + 1;44 45void Example2() {46  constexpr int A          = 42LL;47  constexpr signed short B = ULLONG_MAX;48  // expected-error@-1 {{constexpr initializer evaluates to 18446744073709551615 which is not exactly representable in type 'const short'}}49  constexpr float C        = 47u;50 51  constexpr float D = 432000000;52  constexpr float E = 1.0 / 3.0;53  // expected-error@-1 {{constexpr initializer evaluates to 3.333333e-01 which is not exactly representable in type 'const float'}}54  constexpr float F = 1.0f / 3.0f;55}56 57 58void Example3() {59  constexpr static unsigned short array[] = {60      3000,61      300000,62      // expected-error@-1 {{constexpr initializer evaluates to 300000 which is not exactly representable in type 'const unsigned short'}}63      -164      // expected-error@-1 {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned short'}}65  };66 67  constexpr static unsigned short array1[] = {68      3000,69      3000,70      -171       // expected-error@-1 {{constexpr initializer evaluates to -1 which is not exactly representable in type 'const unsigned short'}}72  };73 74  struct S {75      int x, y;76  };77  constexpr struct S s = {78      .x = __INT_MAX__,79      .y = UINT_MAX,80      // expected-error@-1 {{constexpr initializer evaluates to 4294967295 which is not exactly representable in type 'int'}}81  };82}83 84void Example4() {85  struct s { void *p; };86  constexpr struct s A = { nullptr };87  constexpr struct s B = A;88}89