From 65371a7eddd37f9d5d15790486296cb441cabb40 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 6 Nov 2017 17:45:55 +0000 Subject: [PATCH] re PR c++/65579 ([C++11] gcc requires definition of a static constexpr member even though it is not odr-used) /cp 2017-11-06 Paolo Carlini PR c++/65579 * decl2.c (finish_static_data_member_decl): If there's an initializer, complete the type and re-apply the quals. /testsuite 2017-11-06 Paolo Carlini PR c++/65579 * g++.dg/cpp0x/constexpr-template11.C: New. From-SVN: r254461 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 9 +++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bb90b5a..2a6143a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-11-06 Paolo Carlini + + PR c++/65579 + * decl2.c (finish_static_data_member_decl): If there's an initializer, + complete the type and re-apply the quals. + 2017-11-06 Martin Liska PR middle-end/82404 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index a23b96c..0b18308 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -787,6 +787,15 @@ finish_static_data_member_decl (tree decl, && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE) SET_VAR_HAD_UNKNOWN_BOUND (decl); + if (init) + { + /* Similarly to start_decl_1, we want to complete the type in order + to do the right thing in cp_apply_type_quals_to_decl, possibly + clear TYPE_QUAL_CONST (c++/65579). */ + tree type = TREE_TYPE (decl) = complete_type (TREE_TYPE (decl)); + cp_apply_type_quals_to_decl (cp_type_quals (type), decl); + } + cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index edb3797..b8f7d93 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-06 Paolo Carlini + + PR c++/65579 + * g++.dg/cpp0x/constexpr-template11.C: New. + 2017-11-06 Jakub Jelinek PR tree-optimization/82838 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C new file mode 100644 index 0000000..0ad4908 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C @@ -0,0 +1,16 @@ +// PR c++/65579 +// { dg-do link { target c++11 } } + +template +struct S { + int i; +}; + +struct T { + static constexpr S s = { 1 }; +}; + +int main() +{ + return T::s.i; +} -- 2.7.4