From fdf565deae60707c7484c3d9226ff2ca5622b263 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 30 Aug 2012 22:49:42 -0400 Subject: [PATCH] decl.c (cp_finish_decl): Check for invalid multiple initializers even if the initializer is dependent. * decl.c (cp_finish_decl): Check for invalid multiple initializers even if the initializer is dependent. From-SVN: r190826 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/decl.c | 11 +++++++++-- gcc/testsuite/g++.dg/template/static30.C | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2eca6785b26..1baeaf1a2b7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2012-08-30 Jason Merrill + * 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. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4b2958c5eee..19485fc712c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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; diff --git a/gcc/testsuite/g++.dg/template/static30.C b/gcc/testsuite/g++.dg/template/static30.C index 01fa5dc1e0e..07dafe23ffa 100644 --- a/gcc/testsuite/g++.dg/template/static30.C +++ b/gcc/testsuite/g++.dg/template/static30.C @@ -7,4 +7,4 @@ template struct A }; template const int A::i1(A::i); -template const int A::i2(3, A::i); +template const int A::i2(3, A::i); // { dg-error "expression list" } -- 2.30.2