OSDN Git Service

PR c++/48657
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Apr 2011 19:39:26 +0000 (19:39 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Apr 2011 19:39:26 +0000 (19:39 +0000)
* 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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/const4.C [new file with mode: 0644]

index 19bac65..4fc569a 100644 (file)
@@ -1,3 +1,9 @@
+2011-04-20  Jason Merrill  <jason@redhat.com>
+
+       PR c++/48657
+       * decl.c (cp_finish_decl): Handle non-member constant variables
+       in templates, too.
+
 2011-04-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/46304
index 41beef3..61b57ea 100644 (file)
@@ -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.,
index ea51961..a956416 100644 (file)
@@ -1,3 +1,7 @@
+2011-04-20  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/template/const4.C: New.
+
 2011-04-19  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/ext/complex7.C: New.
diff --git a/gcc/testsuite/g++.dg/template/const4.C b/gcc/testsuite/g++.dg/template/const4.C
new file mode 100644 (file)
index 0000000..6552ec6
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/48657
+
+template<unsigned> struct A { typedef int T; };
+
+template<unsigned> void f()
+{
+  const unsigned D = 4;
+  A<D>::T t;
+}