From: Paolo Carlini Date: Mon, 6 Nov 2017 17:45:55 +0000 (+0000) Subject: re PR c++/65579 ([C++11] gcc requires definition of a static constexpr member even... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=65371a7eddd37f9d5d15790486296cb441cabb40;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bb90b5ac4da..2a6143a2f47 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 a23b96c53e7..0b183085e0e 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 edb3797cc1d..b8f7d931ef3 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 00000000000..0ad49088ad1 --- /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; +}