aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-12-03 15:32:31 +0100
committerJakub Jelinek <jakub@redhat.com>2020-12-03 15:32:31 +0100
commit341035a54aa8954c66b0492f366b8c65fdb34299 (patch)
tree3c9137ff9797a56507901a500878ff10008a903e /gcc
parent614aff0adf8fba5d843ec894603160151c20f0aa (diff)
downloadgcc-341035a54aa8954c66b0492f366b8c65fdb34299.zip
gcc-341035a54aa8954c66b0492f366b8c65fdb34299.tar.gz
gcc-341035a54aa8954c66b0492f366b8c65fdb34299.tar.bz2
c++: consteval-defarg1.C test variant for templates
We weren't recognizing a default argument for a consteval member function as being in immediate function context because there was no function parameter scope to look at. The following testcase is an attempt to test it with templates, both non-dependent and dependent consteval calls in both function and class templates, and with r11-5694 it now passes. 2020-12-03 Jakub Jelinek <jakub@redhat.com> * g++.dg/cpp2a/consteval-defarg2.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/consteval-defarg2.C29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-defarg2.C b/gcc/testsuite/g++.dg/cpp2a/consteval-defarg2.C
new file mode 100644
index 0000000..e8462c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval-defarg2.C
@@ -0,0 +1,29 @@
+// Test that late-parsed default args have the same consteval semantics.
+// { dg-do compile { target c++20 } }
+
+template <int N>
+consteval bool foo (bool x) { if (x) throw N; return false; }
+consteval bool qux (bool x) { if (x) throw 1; return false; }
+template <int N>
+consteval bool bar (bool x = foo<N> (true)) { return true; }
+template <int N>
+consteval bool corge (bool x = qux (true)) { return true; }
+template <int N>
+struct S
+{
+ consteval static bool baz (bool x = foo<N> (true)) { return true; }
+ consteval static bool garply (bool x = qux (true)) { return true; }
+};
+struct T
+{
+ template <int N>
+ consteval static bool baz (bool x = foo<N> (true)) { return true; }
+ template <int N>
+ consteval static bool garply (bool x = qux (true)) { return true; }
+};
+constexpr bool a = bar<0> (true);
+constexpr bool b = corge<0> (true);
+constexpr bool c = S<0>::baz (true);
+constexpr bool d = S<0>::garply (true);
+constexpr bool e = T::baz<0> (true);
+constexpr bool f = T::garply<0> (true);