3 // { dg-options "-std=c++14 -fsanitize=undefined,float-divide-by-zero,float-cast-overflow" }
5 #define SA(X) static_assert((X),#X)
6 #define INT_MIN (-__INT_MAX__ - 1)
13 // { dg-error "5 << -2.. is negative" "" { target *-*-* } .-1 }
14 // { dg-error "is >= than the precision of the left operand" "" { target *-*-* } .-2 }
15 // { dg-error "-2 << 4.. is negative" "" { target *-*-* } .-3 }
19 constexpr int i1 = fn1 (5, 3);
20 constexpr int i2 = fn1 (5, -2); // { dg-message "in .constexpr. expansion" }
21 constexpr int i3 = fn1 (5, sizeof (int) * __CHAR_BIT__); // { dg-message "in .constexpr. expansion" }
22 constexpr int i4 = fn1 (5, 256); // { dg-message "in .constexpr. expansion" }
23 constexpr int i5 = fn1 (5, 2);
24 constexpr int i6 = fn1 (-2, 4); // { dg-message "in .constexpr. expansion" }
25 constexpr int i7 = fn1 (0, 2);
36 // { dg-error "4 >> -1.. is negative" "" { target *-*-* } .-1 }
37 // { dg-error "is >= than the precision of the left operand" "" { target *-*-* } .-2 }
42 constexpr int j1 = fn2 (4, 1);
43 constexpr int j2 = fn2 (4, -1); // { dg-message "in .constexpr. expansion" }
44 constexpr int j3 = fn2 (10, sizeof (int) * __CHAR_BIT__); // { dg-message "in .constexpr. expansion" }
45 constexpr int j4 = fn2 (1, 256); // { dg-message "in .constexpr. expansion" }
46 constexpr int j5 = fn2 (5, 2);
47 constexpr int j6 = fn2 (-2, 4);
48 constexpr int j7 = fn2 (0, 4);
58 a = a / b; // { dg-error "..7 / 0.. is not a constant expression" }
62 constexpr int k1 = fn3 (8, 4);
63 constexpr int k2 = fn3 (7, 0); // { dg-message "in .constexpr. expansion" }
64 constexpr int k3 = fn3 (INT_MIN, -1); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
69 fn4 (float a, float b)
72 a = a / b; // { dg-error "is not a constant expression" }
76 constexpr float l1 = fn4 (5.0, 3.0);
77 constexpr float l2 = fn4 (7.0, 0.0); // { dg-message "in .constexpr. expansion" }
80 fn5 (const int *a, int b)
87 constexpr int m1[4] = { 1, 2, 3, 4 };
88 constexpr int m2 = fn5 (m1, 3);
89 constexpr int m3 = fn5 (m1, 4); // { dg-error "array subscript|in .constexpr. expansion of " }
92 fn6 (const int &a, int b)
100 fn7 (const int *a, int b)
107 constexpr int n1 = 7;
108 constexpr int n2 = fn7 (&n1, 5);
109 constexpr int n3 = fn7 ((const int *) 0, 8); // { dg-error "null pointer|in .constexpr. expansion of " }
114 constexpr int g[10] = { };
118 constexpr int o1 = fn8 (9);
119 constexpr int o2 = fn8 (10); // { dg-error "array subscript|in .constexpr. expansion of " }
129 constexpr int p1 = fn9 (42, 7);
130 constexpr int p2 = fn9 (__INT_MAX__, 1); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
131 constexpr int p3 = fn9 (__INT_MAX__, -1);
132 constexpr int p4 = fn9 (INT_MIN, 1);
133 constexpr int p5 = fn9 (INT_MIN, -1); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
136 SA (p3 == __INT_MAX__ - 1);
137 SA (p4 == INT_MIN + 1);
147 constexpr int q1 = fn10 (10, 10);
148 constexpr int q2 = fn10 (__INT_MAX__, 2); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
149 constexpr int q3 = fn10 (INT_MIN, 2); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
150 constexpr int q4 = fn10 (-1, -1);
164 constexpr int r1 = fn11 (3.4);
165 constexpr int r2 = fn11 (__builtin_inf ()); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }
171 __builtin_unreachable (); // { dg-error "is not a constant expression" }
175 constexpr int s1 = fn12 (1);
176 constexpr int s2 = fn12 (42); // { dg-message "in .constexpr. expansion of " }