Patchwork C++ PATCH for c++/55685 (ICE with sizeof in template)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 15, 2012, 4:02 a.m.
Message ID <50CBF65E.8080308@redhat.com>
Download mbox | patch
Permalink /patch/206602/
State New
Headers show

Comments

Jason Merrill - Dec. 15, 2012, 4:02 a.m.
Here the problem was that tsubst_copy_and_build wasn't guarding the 
SIZEOF_EXPR_TYPE_P code with processing_template_decl like we do in the 
parser.  It's still necessary here because sometimes tsubsting happens 
when we're still in a template.  Fixed by updating the code to match.

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

Patch

commit f415d192e2b16069344b5b9bea9c48dc2a217f99
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Dec 14 16:10:39 2012 -0500

    	PR c++/55685
    	* pt.c (tsubst_copy_and_build): Don't use SIZEOF_EXPR_TYPE_P in
    	templates.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 91450d8..a21522b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13563,7 +13563,7 @@  tsubst_copy_and_build (tree t,
 	  {
 	    if (TREE_CODE (r) != SIZEOF_EXPR || TYPE_P (op1))
 	      {
-		if (TYPE_P (op1))
+		if (!processing_template_decl && TYPE_P (op1))
 		  {
 		    r = build_min (SIZEOF_EXPR, size_type_node,
 				   build1 (NOP_EXPR, op1, error_mark_node));
diff --git a/gcc/testsuite/g++.dg/template/sizeof15.C b/gcc/testsuite/g++.dg/template/sizeof15.C
new file mode 100644
index 0000000..3298dad3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof15.C
@@ -0,0 +1,13 @@ 
+// PR c++/55685
+
+typedef __SIZE_TYPE__ size_t;
+template <size_t T, size_t U>
+struct A;
+
+template <typename T> struct B
+{
+  static A <sizeof (T), 0> x;
+};
+
+template <typename T>
+A <sizeof (T), 0> B <T>::x;