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 // rounding-no-diagnostics
4 
5 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
6 
7 constexpr double a = 1.0 / 3.0;
8 
f(int n)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 
f(Bitfield & b)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 
g()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 
h()39 int *h() {
40   return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}}
41 }
42 
43 
44 // nextUp(1.F) == 0x1.000002p0F
45 static_assert(1.0F + 0x0.000001p0F == 0x1.0p0F, "");
46 
47 char Arr01[1 + (1.0F + 0x0.000001p0F > 1.0F)];
48 static_assert(sizeof(Arr01) == 1, "");
49 
50 struct S1 {
51   int : (1.0F + 0x0.000001p0F > 1.0F);
52   int f;
53 };
54 static_assert(sizeof(S1) == sizeof(int), "");
55 
56 #pragma STDC FENV_ROUND FE_UPWARD
57 static_assert(1.0F + 0x0.000001p0F == 0x1.000002p0F, "");
58 
59 char Arr01u[1 + (1.0F + 0x0.000001p0F > 1.0F)];
60 static_assert(sizeof(Arr01u) == 2, "");
61 
62 struct S1u {
63   int : (1.0F + 0x0.000001p0F > 1.0F);
64   int f;
65 };
66 static_assert(sizeof(S1u) > sizeof(int), "");
67 
68 #pragma STDC FENV_ROUND FE_DOWNWARD
69 static_assert(1.0F + 0x0.000001p0F == 1.0F, "");
70 
71 char Arr01d[1 + (1.0F + 0x0.000001p0F > 1.0F)];
72 static_assert(sizeof(Arr01d) == 1, "");
73 
74 struct S1d {
75   int : (1.0F + 0x0.000001p0F > 1.0F);
76   int f;
77 };
78 static_assert(sizeof(S1d) == sizeof(int), "");
79