]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (cp_finish_decl): Check for invalid multiple initializers even if the initiali...
authorJason Merrill <jason@redhat.com>
Fri, 31 Aug 2012 02:49:42 +0000 (22:49 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 31 Aug 2012 02:49:42 +0000 (22:49 -0400)
* decl.c (cp_finish_decl): Check for invalid multiple initializers
even if the initializer is dependent.

From-SVN: r190826

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/template/static30.C

index 2eca6785b26dba6a23d405076db134b4c26d4f0a..1baeaf1a2b7b7362bb16ffda0400ef84e4654fd7 100644 (file)
@@ -1,5 +1,8 @@
 2012-08-30  Jason Merrill  <jason@redhat.com>
 
+       * decl.c (cp_finish_decl): Check for invalid multiple initializers
+       even if the initializer is dependent.
+
        * pt.c (instantiate_template_1): Keep processing_template_decl set
        if there are dependent args.
 
index 4b2958c5eee29e5a38bb31dab9b4620892ae85b6..19485fc712c0cab180061004b47396580f155935 100644 (file)
@@ -6123,8 +6123,15 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
          release_tree_vector (cleanups);
        }
       else if (!DECL_PRETTY_FUNCTION_P (decl))
-       /* Deduce array size even if the initializer is dependent.  */
-       maybe_deduce_size_from_array_init (decl, init);
+       {
+         /* Deduce array size even if the initializer is dependent.  */
+         maybe_deduce_size_from_array_init (decl, init);
+         /* And complain about multiple initializers.  */
+         if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
+             && !MAYBE_CLASS_TYPE_P (type))
+           init = build_x_compound_expr_from_list (init, ELK_INIT,
+                                                   tf_warning_or_error);
+       }
 
       if (init)
        DECL_INITIAL (decl) = init;
index 01fa5dc1e0ee544b39f7d42344d5616f4db7148a..07dafe23ffaab29f8d84df3caebef01bcb6393f4 100644 (file)
@@ -7,4 +7,4 @@ template <int> struct A
 };
 
 template <int N> const int A<N>::i1(A<N>::i);
-template <int N> const int A<N>::i2(3, A<N>::i);
+template <int N> const int A<N>::i2(3, A<N>::i); // { dg-error "expression list" }