From: Jason Merrill Date: Mon, 9 May 2011 18:00:37 +0000 (-0400) Subject: re PR c++/48936 (sizeof template parm not considered constant expression) X-Git-Tag: releases/gcc-4.4.7~411 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1442bcc8418cb1432f8b9842dde8775da6b83595;p=thirdparty%2Fgcc.git re PR c++/48936 (sizeof template parm not considered constant expression) PR c++/48936 * decl2.c (mark_used): Instantiate constant variables even in unevaluated context. From-SVN: r173585 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ffc7e8c4c33c..a85d3b1f5cbb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-05-09 Jason Merrill + + PR c++/48936 + * decl2.c (mark_used): Instantiate constant variables even + in unevaluated context. + 2011-04-26 Jason Merrill PR c++/42687 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 947256baf43c..7bfe77370112 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -3801,8 +3801,6 @@ possibly_inlined_p (tree decl) void mark_used (tree decl) { - HOST_WIDE_INT saved_processing_template_decl = 0; - /* If DECL is a BASELINK for a single function, then treat it just like the DECL for the function. Otherwise, if the BASELINK is for an overloaded function, we don't know which function was @@ -3825,9 +3823,6 @@ mark_used (tree decl) error ("used here"); return; } - /* If we don't need a value, then we don't need to synthesize DECL. */ - if (skip_evaluation) - return; /* If within finish_function, defer the rest until that function finishes, otherwise it might recurse. */ @@ -3841,9 +3836,10 @@ mark_used (tree decl) DECL. However, if DECL is a static data member initialized with a constant, we need the value right now because a reference to such a data member is not value-dependent. */ - if (TREE_CODE (decl) == VAR_DECL - && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) - && DECL_CLASS_SCOPE_P (decl)) + if (DECL_INTEGRAL_CONSTANT_VAR_P (decl) + && !DECL_INITIAL (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_INSTANTIATION (decl)) { /* Don't try to instantiate members of dependent types. We cannot just use dependent_type_p here because this function @@ -3853,12 +3849,14 @@ mark_used (tree decl) if (CLASSTYPE_TEMPLATE_INFO ((DECL_CONTEXT (decl))) && uses_template_parms (CLASSTYPE_TI_ARGS (DECL_CONTEXT (decl)))) return; - /* Pretend that we are not in a template, even if we are, so - that the static data member initializer will be processed. */ - saved_processing_template_decl = processing_template_decl; - processing_template_decl = 0; + instantiate_decl (decl, /*defer_ok=*/false, + /*expl_inst_class_mem_p=*/false); } + /* If we don't need a value, then we don't need to synthesize DECL. */ + if (skip_evaluation) + return; + if (processing_template_decl) return; @@ -3918,8 +3916,6 @@ mark_used (tree decl) need. Therefore, we always try to defer instantiation. */ instantiate_decl (decl, /*defer_ok=*/true, /*expl_inst_class_mem_p=*/false); - - processing_template_decl = saved_processing_template_decl; } /* Given function PARM_DECL PARM, return its index in the function's list diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3db91f31bfc..e22b269a4a20 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-05-09 Jason Merrill + + * g++.dg/template/nontype23.C: New. + 2011-05-05 Jason Merrill * g++.dg/init/new30.C: New. diff --git a/gcc/testsuite/g++.dg/template/nontype23.C b/gcc/testsuite/g++.dg/template/nontype23.C new file mode 100644 index 000000000000..dfda4fe2e595 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/nontype23.C @@ -0,0 +1,9 @@ +// PR c++/48936 + +template int foo (void); +template struct S +{ + static const unsigned int a = sizeof (T); + enum { c = sizeof (foo <(a == 0)> ()) }; +}; +S x;