blob: 3577d2fc0756e9130002c16a4978bab15a1f3a6f [file] [log] [blame]
Richard Smith7e801ca2020-10-13 19:14:13 -07001// 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
7constexpr double a = 1.0 / 3.0;
8
9constexpr int f(int n) { return int(n * (1.0 / 3.0)); }
10
11using T = int[f(3)];
12using T = int[1];
13
14enum Enum { enum_a = f(3) };
15
16struct Bitfield {
17 unsigned int n : 1;
18 unsigned int m : f(3);
19};
20
21void f(Bitfield &b) {
22 b.n = int(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}}
23}
24
25const int k = 3 * (1.0 / 3.0);
26static_assert(k == 1, "");
27
28void 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
39int *h() {
40 return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}}
41}