1 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding %s 2 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math 3 // rounding-no-diagnostics 4 5 #define fold(x) (__builtin_constant_p(x) ? (x) : (x)) 6 7 constexpr double a = 1.0 / 3.0; 8 9 constexpr int f(int n) { return int(n * (1.0 / 3.0)); } 10 11 using T = int[f(3)]; 12 using T = int[1]; 13 14 enum Enum { enum_a = f(3) }; 15 16 struct Bitfield { 17 unsigned int n : 1; 18 unsigned int m : f(3); 19 }; 20 21 void f(Bitfield &b) { 22 b.n = int(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}} 23 } 24 25 const int k = 3 * (1.0 / 3.0); 26 static_assert(k == 1, ""); 27 28 void g() { 29 // FIXME: Constant-evaluating this initializer is surprising, and violates 30 // the recommended practice in C++ [expr.const]p12: 31 // 32 // Implementations should provide consistent results of floating-point 33 // evaluations, irrespective of whether the evaluation is performed during 34 // translation or during program execution. 35 const int k = 3 * (1.0 / 3.0); 36 static_assert(k == 1, ""); 37 } 38 39 int *h() { 40 return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}} 41 } 42