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]

PR c++/29518


This patch fixes (yet another) template static data member problem.
The problem here is that we do not bother to instantiate a static data
member inside sizeof, because we do not need the value of the data
member.  However, if we're inside a template parameter list inside a
sizeof, we do need the value.  We were already handling this correctly
during parsing, due to:

  2005-09-16  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23914
	* parser.c (cp_parser_enclosed_template_argument_list): Make sure
	skip_evaluation is false when processing template arguments.

but, we need to do the same thing during substitution into template
parameter lists during template instantiation.

Tested on x86_64-unknown-linux-gnu, applied to mainline.  I will apply
to the 4.1 and 4.2 branches after testing completes.

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

2006-11-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29518
	* pt.c (coerce_template_parms): Do not skip_evaluation while
	substituting template arguments.

2006-11-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29518
	* g++.dg/template/static28.C: New test.

Index: gcc/testsuite/g++.dg/template/static28.C
===================================================================
--- gcc/testsuite/g++.dg/template/static28.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/static28.C	(revision 0)
@@ -0,0 +1,15 @@
+// PR c++/29518
+
+template< bool C > int assertion_failed( int);
+template< class > 
+struct N
+{
+  static bool const okay = true;
+  enum {
+    t = sizeof( assertion_failed<okay>( 0))
+  };
+};
+int main()
+{
+  N<int> n;
+}
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 118764)
+++ gcc/cp/pt.c	(working copy)
@@ -4131,6 +4131,7 @@ coerce_template_parms (tree parms,
   tree inner_args;
   tree new_args;
   tree new_inner_args;
+  bool saved_skip_evaluation;
 
   inner_args = INNERMOST_TEMPLATE_ARGS (args);
   nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0;
@@ -4155,6 +4156,10 @@ coerce_template_parms (tree parms,
       return error_mark_node;
     }
 
+  /* We need to evaluate the template arguments, even though this
+     template-id may be nested within a "sizeof".  */
+  saved_skip_evaluation = skip_evaluation;
+  skip_evaluation = false;
   new_inner_args = make_tree_vec (nparms);
   new_args = add_outermost_template_args (args, new_inner_args);
   for (i = 0; i < nparms; i++)
@@ -4196,6 +4201,7 @@ coerce_template_parms (tree parms,
 	lost++;
       TREE_VEC_ELT (new_inner_args, i) = arg;
     }
+  skip_evaluation = saved_skip_evaluation;
 
   if (lost)
     return error_mark_node;
@@ -7261,7 +7267,6 @@ tsubst (tree t, tree args, tsubst_flags_
 
 	max = tsubst_expr (omax, args, complain, in_decl,
 			   /*integral_constant_expression_p=*/false);
-	max = fold_non_dependent_expr (max);
 	max = fold_decl_constant_value (max);
 
 	if (TREE_CODE (max) != INTEGER_CST 


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