Upstream-Status: Inappropriate [Backport] From 03be58e53f230926009974bd7aed6a40a557dc1d Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 20 Apr 2011 19:39:26 +0000 Subject: [PATCH 156/200] PR c++/48657 * decl.c (cp_finish_decl): Handle non-member constant variables in templates, too. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172791 138bc75d-0d04-0410-961f-82ee72b054a4 index 41beef3..61b57ea 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5862,11 +5862,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, 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) + && init_const_expr_p && !type_dependent_p - /* FIXME non-value-dependent constant expression */ + && decl_maybe_constant_var_p (decl) && !value_dependent_init_p (init))) { if (init) @@ -5878,6 +5876,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, goto finish_end; } + if (!DECL_CLASS_SCOPE_P (decl)) + { + tree init_code = check_initializer (decl, init, flags, &cleanup); + if (init_code) + DECL_INITIAL (decl) = init; + goto finish_end; + } + if (TREE_CODE (init) == TREE_LIST) { /* If the parenthesized-initializer form was used (e.g., new file mode 100644 index 0000000..6552ec6 --- /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; +} -- 1.7.0.4