This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 29435


This patch fixes an ICE-on-valid regression when sizeof is applied to
a complete, but uninstantiated template class.  We need to try to
complete the type, if it is non-dependent.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
apply this patch to the 4.1 branch once testing completes.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-10-16  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29435
	* typeck.c (cxx_sizeof_or_alignof_type): Complete non-dependent
	types when their sizes are required.  Refine test for VLAs.

2006-10-16  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29435
	* g++.dg/template/sizeof11.C: New test.

Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 117789)
+++ gcc/cp/typeck.c	(working copy)
@@ -1242,6 +1242,7 @@ tree
 cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
 {
   tree value;
+  bool dependent_p;
 
   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
   if (type == error_mark_node)
@@ -1256,15 +1257,19 @@ cxx_sizeof_or_alignof_type (tree type, e
       value = size_one_node;
     }
 
-  if (dependent_type_p (type)
+  dependent_p = dependent_type_p (type);
+  if (!dependent_p)
+    complete_type (type);
+  if (dependent_p
       /* VLA types will have a non-constant size.  In the body of an
 	 uninstantiated template, we don't need to try to compute the
 	 value, because the sizeof expression is not an integral
 	 constant expression in that case.  And, if we do try to
 	 compute the value, we'll likely end up with SAVE_EXPRs, which
 	 the template substitution machinery does not expect to see.  */
-      || (processing_template_decl && 
-	  TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
+      || (processing_template_decl 
+	  && COMPLETE_TYPE_P (type)
+	  && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
     {
       value = build_min (op, size_type_node, type);
       TREE_READONLY (value) = 1;
Index: gcc/testsuite/g++.dg/template/sizeof11.C
===================================================================
--- gcc/testsuite/g++.dg/template/sizeof11.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/sizeof11.C	(revision 0)
@@ -0,0 +1,14 @@
+// PR c++/29435
+
+template < class T > struct A {};
+template < int> void g()
+{
+  sizeof (A < int>);
+}
+
+template < class T > struct B;
+template < int> void f()
+{
+  sizeof (B<int>); // { dg-error "incomplete" }
+}
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]