From 763e303a73079eb88f480534541f86a63a02c754 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 6 Sep 2007 19:19:15 +0000 Subject: [PATCH] re PR c++/32674 (ICE in lvalue_p_1 initialising static variable inside template class) /cp 2007-09-06 Paolo Carlini PR c++/32674 * decl.c (cp_finish_decl): When processing_template_decl, deal correctly with init as TREE_LIST. /testsuite 2007-09-06 Paolo Carlini PR c++/32674 * g++.dg/template/static31.C: New. From-SVN: r128205 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 16 +++++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/static31.C | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/static31.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 25806cee78d7..8cea1221e733 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-09-06 Paolo Carlini + + PR c++/32674 + * decl.c (cp_finish_decl): When processing_template_decl, + deal correctly with init as TREE_LIST. + 2007-09-05 Paolo Carlini PR c++/33210 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3fee2763fc56..5b5858df7cd5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5214,7 +5214,21 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, goto finish_end; } - init = fold_non_dependent_expr (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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 22977f9fb210..2643d8407f84 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-06 Paolo Carlini + + PR c++/32674 + * g++.dg/template/static31.C: New. + 2007-09-06 David Daney Richard Sandiford diff --git a/gcc/testsuite/g++.dg/template/static31.C b/gcc/testsuite/g++.dg/template/static31.C new file mode 100644 index 000000000000..935a8a790fa4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/static31.C @@ -0,0 +1,19 @@ +// PR c++/32674 + +class C +{ + static const int j = 3; +}; + +template class A +{ + static const int i1; + static const int i2; + static const int i3; + static const int i4; +}; + +template const int A::i1(C::j); +template const int A::i2 = C::j; +template const int A::i3(C::j, 5); // { dg-error "compound expression" } +template const int A::i4 = (C::j, 7); -- 2.47.2