Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval-defarg2.C

raw
1 // Test that late-parsed default args have the same consteval semantics.
2 // { dg-do compile { target c++20 } }
3
4 template <int N>
5 consteval bool foo (bool x) { if (x) throw N; return false; }
6 consteval bool qux (bool x) { if (x) throw 1; return false; }
7 template <int N>
8 consteval bool bar (bool x = foo<N> (true)) { return true; }
9 template <int N>
10 consteval bool corge (bool x = qux (true)) { return true; }
11 template <int N>
12 struct S
13 {
14 consteval static bool baz (bool x = foo<N> (true)) { return true; }
15 consteval static bool garply (bool x = qux (true)) { return true; }
16 };
17 struct T
18 {
19 template <int N>
20 consteval static bool baz (bool x = foo<N> (true)) { return true; }
21 template <int N>
22 consteval static bool garply (bool x = qux (true)) { return true; }
23 };
24 constexpr bool a = bar<0> (true);
25 constexpr bool b = corge<0> (true);
26 constexpr bool c = S<0>::baz (true);
27 constexpr bool d = S<0>::garply (true);
28 constexpr bool e = T::baz<0> (true);
29 constexpr bool f = T::garply<0> (true);