From 8efcbecad561cde32bdefe8d08f096e6284ef928 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 20 Apr 2011 15:39:02 -0400 Subject: [PATCH] =?utf8?q?re=20PR=20c++/48657=20(could=20not=20convert=20t?= =?utf8?q?emplate=20argument=20=E2=80=98VectorDimension=E2=80=99=20to=20?= =?utf8?q?=E2=80=98unsigned=20int=E2=80=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR c++/48657 * decl.c (cp_finish_decl): Simplify template handling. From-SVN: r172790 --- gcc/cp/ChangeLog | 5 +++ gcc/cp/decl.c | 62 +++++++++----------------- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/g++.dg/template/const4.C | 9 ++++ 4 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/const4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e854651ecb6..ed9871973bc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-04-20 Jason Merrill + + PR c++/48657 + * decl.c (cp_finish_decl): Simplify template handling. + 2011-04-20 Jim Meyering * tree.c (cxx_printable_name_internal): Remove useless if-before-free. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 63096485ffe..cf4a40efed3 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5750,7 +5750,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, const char *asmspec = NULL; int was_readonly = 0; bool var_definition_p = false; - int saved_processing_template_decl; tree auto_node; if (decl == error_mark_node) @@ -5772,7 +5771,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* Assume no cleanup is required. */ cleanup = NULL_TREE; - saved_processing_template_decl = processing_template_decl; /* If a name was specified, get the string. */ if (global_scope_p (current_binding_level)) @@ -5878,39 +5876,24 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, template is instantiated. But, if DECL is a variable constant then it can be used in future constant expressions, so its value must be available. */ - if (!(init - && DECL_CLASS_SCOPE_P (decl) - /* We just set TREE_CONSTANT appropriately; see above. */ - && TREE_CONSTANT (decl) - && !type_dependent_p - /* FIXME non-value-dependent constant expression */ - && !value_dependent_init_p (init))) - { - if (init) - DECL_INITIAL (decl) = init; - if (TREE_CODE (decl) == VAR_DECL - && !DECL_PRETTY_FUNCTION_P (decl) - && !type_dependent_p) - maybe_deduce_size_from_array_init (decl, init); - goto finish_end; + if (init + && init_const_expr_p + && !type_dependent_p + && decl_maybe_constant_var_p (decl) + && !value_dependent_init_p (init)) + { + tree init_code = check_initializer (decl, init, flags, &cleanup); + if (init_code == NULL_TREE) + init = NULL_TREE; } + else if (TREE_CODE (decl) == VAR_DECL + && !DECL_PRETTY_FUNCTION_P (decl) + && !type_dependent_p) + maybe_deduce_size_from_array_init (decl, init); - if (TREE_CODE (init) == TREE_LIST) - { - /* If the parenthesized-initializer form was used (e.g., - "int A::i(X)"), then INIT will be a TREE_LIST of initializer - arguments. (There is generally only one.) We convert them - individually. */ - tree list = init; - for (; list; list = TREE_CHAIN (list)) - { - tree elt = TREE_VALUE (list); - TREE_VALUE (list) = fold_non_dependent_expr (elt); - } - } - else - init = fold_non_dependent_expr (init); - processing_template_decl = 0; + if (init) + DECL_INITIAL (decl) = init; + return; } /* Take care of TYPE_DECLs up front. */ @@ -5933,7 +5916,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), at_eof); - goto finish_end; + return; } /* A reference will be modified here, as it is initialized. */ @@ -6057,8 +6040,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, else if (TREE_CODE (type) == ARRAY_TYPE) layout_type (type); - if (!processing_template_decl - && TREE_STATIC (decl) + if (TREE_STATIC (decl) && !at_function_scope_p () && current_function_decl == NULL) /* So decl is a global variable or a static member of a @@ -6078,9 +6060,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* Let the middle end know about variables and functions -- but not static data members in uninstantiated class templates. */ - if (!saved_processing_template_decl - && (TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL)) + if (TREE_CODE (decl) == VAR_DECL + || TREE_CODE (decl) == FUNCTION_DECL) { if (TREE_CODE (decl) == VAR_DECL) { @@ -6167,9 +6148,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (cleanup) push_cleanup (decl, cleanup, false); - finish_end: - processing_template_decl = saved_processing_template_decl; - if (was_readonly) TREE_READONLY (decl) = 1; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dfa5c8c00ce..c16c9bf6574 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-04-20 Jason Merrill + + * g++.dg/template/const4.C: New. + 2011-04-20 Easwaran Raman * gcc.dg/stack-layout-1.c: New test. diff --git a/gcc/testsuite/g++.dg/template/const4.C b/gcc/testsuite/g++.dg/template/const4.C new file mode 100644 index 00000000000..6552ec6e968 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/const4.C @@ -0,0 +1,9 @@ +// PR c++/48657 + +template struct A { typedef int T; }; + +template void f() +{ + const unsigned D = 4; + A::T t; +} -- 2.30.2