1 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s 2 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas 3 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas 4 // rounding-no-diagnostics 5 6 #define fold(x) (__builtin_constant_p(x) ? (x) : (x)) 7 8 constexpr double a = 1.0 / 3.0; 9 10 constexpr int f(int n) { return int(n * (1.0 / 3.0)); } 11 12 using T = int[f(3)]; 13 using T = int[1]; 14 15 enum Enum { enum_a = f(3) }; 16 17 struct Bitfield { 18 unsigned int n : 1; 19 unsigned int m : f(3); 20 }; 21 22 void f(Bitfield &b) { 23 b.n = int(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}} 24 } 25 26 const int k = 3 * (1.0 / 3.0); 27 static_assert(k == 1, ""); 28 29 void g() { 30 // FIXME: Constant-evaluating this initializer is surprising, and violates 31 // the recommended practice in C++ [expr.const]p12: 32 // 33 // Implementations should provide consistent results of floating-point 34 // evaluations, irrespective of whether the evaluation is performed during 35 // translation or during program execution. 36 const int k = 3 * (1.0 / 3.0); 37 static_assert(k == 1, ""); 38 } 39 40 int *h() { 41 return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}} 42 } 43 44 45 // nextUp(1.F) == 0x1.000002p0F 46 static_assert(1.0F + 0x0.000001p0F == 0x1.0p0F, ""); 47 48 char Arr01[1 + (1.0F + 0x0.000001p0F > 1.0F)]; 49 static_assert(sizeof(Arr01) == 1, ""); 50 51 struct S1 { 52 int : (1.0F + 0x0.000001p0F > 1.0F); 53 int f; 54 }; 55 static_assert(sizeof(S1) == sizeof(int), ""); 56 57 #pragma STDC FENV_ROUND FE_UPWARD 58 static_assert(1.0F + 0x0.000001p0F == 0x1.000002p0F, ""); 59 60 char Arr01u[1 + (1.0F + 0x0.000001p0F > 1.0F)]; 61 static_assert(sizeof(Arr01u) == 2, ""); 62 63 struct S1u { 64 int : (1.0F + 0x0.000001p0F > 1.0F); 65 int f; 66 }; 67 static_assert(sizeof(S1u) > sizeof(int), ""); 68 69 #pragma STDC FENV_ROUND FE_DOWNWARD 70 static_assert(1.0F + 0x0.000001p0F == 1.0F, ""); 71 72 char Arr01d[1 + (1.0F + 0x0.000001p0F > 1.0F)]; 73 static_assert(sizeof(Arr01d) == 1, ""); 74 75 struct S1d { 76 int : (1.0F + 0x0.000001p0F > 1.0F); 77 int f; 78 }; 79 static_assert(sizeof(S1d) == sizeof(int), ""); 80