From: Jason Merrill Date: Fri, 8 Jul 2011 14:24:14 +0000 (-0400) Subject: re PR c++/49673 ([C++0x] const variables initialised with constexpr constructor place... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=329af3c7e9317952d68d3522e9e3aa6ac188332a;p=gcc.git re PR c++/49673 ([C++0x] const variables initialised with constexpr constructor placed in .data not .rodata) PR c++/49673 gcc/c-family/ * c-common.c (c_apply_type_quals_to_decl): Don't check TYPE_NEEDS_CONSTRUCTING. gcc/cp/ * typeck.c (cp_apply_type_quals_to_decl): Don't check TYPE_NEEDS_CONSTRUCTING. From-SVN: r176045 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 1e3ca7d1d6a..72a118a942f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2011-07-08 Jason Merrill + + PR c++/49673 + * c-common.c (c_apply_type_quals_to_decl): Don't check + TYPE_NEEDS_CONSTRUCTING. + 2011-07-06 Richard Guenther * c-common.c (c_common_nodes_and_builtins): diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 67291de7d4a..3ffacd5b444 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4058,14 +4058,11 @@ c_apply_type_quals_to_decl (int type_quals, tree decl) if (type == error_mark_node) return; - if (((type_quals & TYPE_QUAL_CONST) - || (type && TREE_CODE (type) == REFERENCE_TYPE)) - /* An object declared 'const' is only readonly after it is - initialized. We don't have any way of expressing this currently, - so we need to be conservative and unset TREE_READONLY for types - with constructors. Otherwise aliasing code will ignore stores in - an inline constructor. */ - && !(type && TYPE_NEEDS_CONSTRUCTING (type))) + if ((type_quals & TYPE_QUAL_CONST) + || (type && TREE_CODE (type) == REFERENCE_TYPE)) + /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr + constructor can produce constant init, so rely on cp_finish_decl to + clear TREE_READONLY if the variable has non-constant init. */ TREE_READONLY (decl) = 1; if (type_quals & TYPE_QUAL_VOLATILE) { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b926ec947a2..469e6cb1a14 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-07-08 Jason Merrill + + PR c++/49673 + * typeck.c (cp_apply_type_quals_to_decl): Don't check + TYPE_NEEDS_CONSTRUCTING. + 2011-07-07 Jason Merrill PR c++/49663 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 2acb18efbae..f0d68c3dca5 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8127,12 +8127,12 @@ cp_apply_type_quals_to_decl (int type_quals, tree decl) && type_quals != TYPE_UNQUALIFIED)); /* Avoid setting TREE_READONLY incorrectly. */ - if (/* If the object has a constructor, the constructor may modify - the object. */ - TYPE_NEEDS_CONSTRUCTING (type) - /* If the type isn't complete, we don't know yet if it will need + /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr + constructor can produce constant init, so rely on cp_finish_decl to + clear TREE_READONLY if the variable has non-constant init. */ + if (/* If the type isn't complete, we don't know yet if it will need constructing. */ - || !COMPLETE_TYPE_P (type) + !COMPLETE_TYPE_P (type) /* If the type has a mutable component, that component might be modified. */ || TYPE_HAS_MUTABLE_P (type)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 360c0aae53d..9393815eab7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-07-08 Jason Merrill + + PR c++/49673 + * g++.dg/cpp0x/constexpr-rom.C: New. + 2011-07-08 Kirill Yukhin PR middle-end/49519 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-rom.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-rom.C new file mode 100644 index 00000000000..e2edb2e345d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-rom.C @@ -0,0 +1,11 @@ +// PR c++/49673: check that test_data goes into .rodata +// { dg-options -std=c++0x } +// { dg-final { scan-assembler "rodata" } } + +struct Data +{ + int i; + constexpr Data(int i = 0) : i(i+1) {} +}; + +extern const Data test_data = { 1 };