public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/66255 (ICE with non-type template parameter of typedef type)
@ 2015-06-26 21:05 Jason Merrill
  2015-06-27 10:59 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2015-06-26 21:05 UTC (permalink / raw)
  To: gcc-patches List

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

My checking code to make sure that we've stripped all appropriate 
typedefs wasn't considering that the parameter might have a typedef 
type, requiring the argument to match.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 66255.patch --]
[-- Type: text/x-patch, Size: 2490 bytes --]

commit 63f562788d442b1139d1158a26129b781c16b07a
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jun 25 12:13:16 2015 -0400

    	PR c++/66255
    	* pt.c (check_unstripped_args): Split out from...
    	(retrieve_specialization): ...here.  Allow typedefs in the type of
    	a non-type argument.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index fe5fc14..082e04c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1019,6 +1019,35 @@ optimize_specialization_lookup_p (tree tmpl)
 	  && !DECL_FRIEND_P (DECL_TEMPLATE_RESULT (tmpl)));
 }
 
+/* Make sure ARGS doesn't use any inappropriate typedefs; we should have
+   gone through coerce_template_parms by now.  */
+
+static void
+check_unstripped_args (tree args)
+{
+#ifdef ENABLE_CHECKING
+  ++processing_template_decl;
+  if (!any_dependent_template_arguments_p (args))
+    {
+      tree inner = INNERMOST_TEMPLATE_ARGS (args);
+      for (int i = 0; i < TREE_VEC_LENGTH (inner); ++i)
+	{
+	  tree arg = TREE_VEC_ELT (inner, i);
+	  if (TREE_CODE (arg) == TEMPLATE_DECL)
+	    /* OK */;
+	  else if (TYPE_P (arg))
+	    gcc_assert (strip_typedefs (arg, NULL) == arg);
+	  else if (strip_typedefs (TREE_TYPE (arg), NULL) != TREE_TYPE (arg))
+	    /* Allow typedefs on the type of a non-type argument, since a
+	       parameter can have them.  */;
+	  else
+	    gcc_assert (strip_typedefs_expr (arg, NULL) == arg);
+	}
+    }
+  --processing_template_decl;
+#endif
+}
+
 /* Retrieve the specialization (in the sense of [temp.spec] - a
    specialization is either an instantiation or an explicit
    specialization) of TMPL for the given template ARGS.  If there is
@@ -1052,13 +1081,7 @@ retrieve_specialization (tree tmpl, tree args, hashval_t hash)
 		  ? TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl))
 		  : template_class_depth (DECL_CONTEXT (tmpl))));
 
-#ifdef ENABLE_CHECKING
-  /* We should have gone through coerce_template_parms by now.  */
-  ++processing_template_decl;
-  if (!any_dependent_template_arguments_p (args))
-    gcc_assert (strip_typedefs_expr (args, NULL) == args);
-  --processing_template_decl;
-#endif
+  check_unstripped_args (args);
 
   if (optimize_specialization_lookup_p (tmpl))
     {
diff --git a/gcc/testsuite/g++.dg/template/nontype27.C b/gcc/testsuite/g++.dg/template/nontype27.C
new file mode 100644
index 0000000..956e5e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/nontype27.C
@@ -0,0 +1,9 @@
+// PR c++/66255
+
+typedef int int_t;
+
+template <int_t &>
+struct S { };
+
+int_t a;
+S <a> b;

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

* Re: C++ PATCH for c++/66255 (ICE with non-type template parameter of typedef type)
  2015-06-26 21:05 C++ PATCH for c++/66255 (ICE with non-type template parameter of typedef type) Jason Merrill
@ 2015-06-27 10:59 ` Andreas Schwab
  2015-06-29 18:50   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2015-06-27 10:59 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

	* pt.c (check_unstripped_args): Mark parameter as unused.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 082e04c..ad2970d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1023,7 +1023,7 @@ optimize_specialization_lookup_p (tree tmpl)
    gone through coerce_template_parms by now.  */
 
 static void
-check_unstripped_args (tree args)
+check_unstripped_args (tree args ATTRIBUTE_UNUSED)
 {
 #ifdef ENABLE_CHECKING
   ++processing_template_decl;
-- 
2.4.5

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: C++ PATCH for c++/66255 (ICE with non-type template parameter of typedef type)
  2015-06-27 10:59 ` Andreas Schwab
@ 2015-06-29 18:50   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2015-06-29 18:50 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc-patches List

On 06/27/2015 04:28 AM, Andreas Schwab wrote:
> 	* pt.c (check_unstripped_args): Mark parameter as unused.

Thanks.

Jason


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

end of thread, other threads:[~2015-06-29 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-26 21:05 C++ PATCH for c++/66255 (ICE with non-type template parameter of typedef type) Jason Merrill
2015-06-27 10:59 ` Andreas Schwab
2015-06-29 18:50   ` 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).