public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] replace ICE with error for failed template deduction (PR 84355)
@ 2018-02-15 23:36 Martin Sebor
  2018-02-16 14:04 ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Sebor @ 2018-02-15 23:36 UTC (permalink / raw)
  To: Jason Merrill, Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 326 bytes --]

A failed template deduction in template member of a template
triggers an ICE with -std=c++17 due to what seems like
a missing handling of invalid input.  Replacing
the gcc_unreachable() call that causes the ICE with a return
statement indicating the deduction failure eliminates the ICE
and restores sane diagnostics.

Martin

[-- Attachment #2: gcc-84355.diff --]
[-- Type: text/x-patch, Size: 1388 bytes --]

PR c++/84355 - [7/8 Regression] ICE with failing template argument deduction

gcc/cp/ChangeLog:

	PR c++/84355
	* pt.c (unify): Return failure instead of asserting.

gcc/testsuite/ChangeLog:

	PR c++/84355
	* g++.dg/cpp1z/class-deduction48.C: New test.

Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 257713)
+++ gcc/cp/pt.c	(working copy)
@@ -20918,7 +20918,7 @@ unify (tree tparms, tree targs, tree parm, tree ar
 	   && TREE_CODE (tparm) != TYPE_DECL)
 	  || (TREE_CODE (parm) == TEMPLATE_TEMPLATE_PARM
 	      && TREE_CODE (tparm) != TEMPLATE_DECL))
-	gcc_unreachable ();
+	return unify_invalid (explain_p);
 
       if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
 	{
Index: gcc/testsuite/g++.dg/cpp1z/class-deduction48.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1z/class-deduction48.C	(nonexistent)
+++ gcc/testsuite/g++.dg/cpp1z/class-deduction48.C	(working copy)
@@ -0,0 +1,20 @@
+// PR c++/84355 - ICE with failing template argument deduction
+// { dg-do compile }
+// { dg-options "-std=c++17" }
+
+template <typename T>
+struct A
+{
+  template <int>
+  struct B
+  {
+    B (T);
+  };
+
+  A () {
+    B b (0);   // { dg-error "deduction failed" }
+               // { dg-error "no matching function" "" { target *-*-* } .-1 }
+  }
+};
+
+A<int> a;

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-03-12 14:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 23:36 [PATCH] replace ICE with error for failed template deduction (PR 84355) Martin Sebor
2018-02-16 14:04 ` Jason Merrill
2018-02-16 19:31   ` Jason Merrill
2018-02-16 21:33   ` Martin Sebor
2018-02-19  4:39     ` Jason Merrill
2018-02-24  2:33       ` Jason Merrill
2018-03-06  0:05         ` Martin Sebor
2018-03-12 14:40           ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).