[PR c++/84702] ICE with default tmpl arg of overload set
[official-gcc.git] / gcc / testsuite / g++.dg / ext / builtin-arith-overflow-2.C
blob340ab77b9d771fa8ced0b381c5794410daec1da4
1 // { dg-do run }
2 // { dg-options "-O2" }
4 struct A { int i : 1; };
5 struct B { int j : 3; };
7 template <typename S>
8 int
9 foo (int x, int y)
11   A a = {};
12   S s = {};
13   return __builtin_add_overflow_p (x, y, a.i) + 2 * __builtin_mul_overflow_p (x, y, s.j);
16 __attribute__((noinline, noclone)) int
17 bar (int x, int y)
19   return foo <B> (x, y);
22 #if __cplusplus >= 201402L
23 template <typename S>
24 constexpr int
25 baz (int x, int y)
27   A a = {};
28   S s = {};
29   return __builtin_add_overflow_p (x, y, a.i) + 2 * __builtin_mul_overflow_p (x, y, s.j);
32 constexpr int t1 = baz <B> (0, 0);
33 constexpr int t2 = baz <B> (1, -1);
34 constexpr int t3 = baz <B> (1, -4);
35 constexpr int t4 = baz <B> (-4, 4);
36 constexpr int t5 = baz <B> (4, 2);
37 static_assert (t1 == 0, "");
38 static_assert (t2 == 0, "");
39 static_assert (t3 == 1, "");
40 static_assert (t4 == 2, "");
41 static_assert (t5 == 3, "");
42 #endif
44 int
45 main ()
47   if (bar (0, 0) != 0
48       || bar (-1, 1) != 0
49       || bar (-4, 1) != 1
50       || bar (4, -4) != 2
51       || bar (2, 4) != 3)
52     __builtin_abort ();