145
|
1 // PR c++/70507 - integer overflow builtins not constant expressions
|
|
2 // The constexpr-arith-overflow.C testcase covers this for C++14 and later.
|
|
3 // { dg-do compile }
|
|
4 // { dg-options "-std=c++11" }
|
|
5
|
|
6 #define Assert(expr) static_assert ((expr), #expr)
|
|
7
|
|
8 template <class T>
|
|
9 constexpr T add (T x, T y, T z = T ())
|
|
10 {
|
|
11 return __builtin_add_overflow (x, y, &z) ? 0 : z; // { dg-error "is not a constant expression" }
|
|
12 }
|
|
13
|
|
14 template <class T>
|
|
15 constexpr T sub (T x, T y, T z = T ())
|
|
16 {
|
|
17 return __builtin_sub_overflow (x, y, &z) ? 0 : z; // { dg-error "is not a constant expression" }
|
|
18 }
|
|
19
|
|
20 template <class T>
|
|
21 constexpr T mul (T x, T y, T z = T ())
|
|
22 {
|
|
23 return __builtin_mul_overflow (x, y, &z) ? 0 : z; // { dg-error "is not a constant expression" }
|
|
24 }
|
|
25
|
|
26 Assert (0 == add<int>(0, 0)); // { dg-error "non-constant condition for static assertion" }
|
|
27 Assert (0 == sub<int>(0, 0)); // { dg-error "non-constant condition for static assertion" }
|
|
28 Assert (0 == mul<int>(0, 0)); // { dg-error "non-constant condition for static assertion" }
|
|
29 // { dg-message "expansion of" "" { target *-*-* } .-3 }
|
|
30 // { dg-message "expansion of" "" { target *-*-* } .-3 }
|
|
31 // { dg-message "expansion of" "" { target *-*-* } .-3 }
|