[PATCH] c++: ICE with constrained placeholder return type [PR98346]

Patrick Palka ppalka@redhat.com
Thu Jan 7 21:06:42 GMT 2021


This is essentially a followup to r11-3714 -- we ICEing from another
"unguarded" call to build_concept_check, this time in do_auto_deduction,
due to the presence of templated trees when !processing_template_decl.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk and perhaps the 10 branch?

gcc/cp/ChangeLog:

	PR c++/98346
	* pt.c (do_auto_deduction): Temporarily increment
	processing_template_decl before calling build_concept_check.

gcc/testsuite/ChangeLog:

	PR c++/98346
	* g++.dg/cpp2a/concepts-placeholder3.C: New test.
---
 gcc/cp/pt.c                                       |  2 ++
 .../g++.dg/cpp2a/concepts-placeholder3.C          | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-placeholder3.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index beabcc4b027..111a694e0c5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29464,7 +29464,9 @@ do_auto_deduction (tree type, tree init, tree auto_node,
           cargs = targs;
 
 	/* Rebuild the check using the deduced arguments.  */
+	++processing_template_decl;
 	check = build_concept_check (cdecl, cargs, tf_none);
+	--processing_template_decl;
 
 	if (!constraints_satisfied_p (check))
           {
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder3.C
new file mode 100644
index 00000000000..a5d0b1e1d0f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder3.C
@@ -0,0 +1,15 @@
+// PR c++/98346
+// { dg-do compile { target c++20 } }
+
+template <class, class...>
+concept always_satisfied = true;
+
+using arg_alias = int;
+
+template <always_satisfied F>
+using result_of = decltype(F{}(arg_alias{}));
+
+template <class F>
+always_satisfied<result_of<F>> auto foo(F) {}
+
+void bar() { foo(0); }
-- 
2.30.0



More information about the Gcc-patches mailing list