re PR c++/49673 ([C++0x] const variables initialised with constexpr constructor place...
authorJason Merrill <jason@redhat.com>
Fri, 8 Jul 2011 14:24:14 +0000 (10:24 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 8 Jul 2011 14:24:14 +0000 (10:24 -0400)
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

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-rom.C [new file with mode: 0644]

index 1e3ca7d1d6a94a16c11bb69c92ed33633ba766d2..72a118a942fda2ded8710bd1aedc3b543d38e4dd 100644 (file)
@@ -1,3 +1,9 @@
+2011-07-08  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49673
+       * c-common.c (c_apply_type_quals_to_decl): Don't check
+       TYPE_NEEDS_CONSTRUCTING.
+
 2011-07-06  Richard Guenther  <rguenther@suse.de>
 
        * c-common.c (c_common_nodes_and_builtins):
index 67291de7d4a5b2f026d0adc131a827a775cb465e..3ffacd5b444f03b159956817e80a86d12ffe7106 100644 (file)
@@ -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)
     {
index b926ec947a2e9c47023f2083af0245cc2f37ba15..469e6cb1a146e541595f5520ad5ec317dc184d62 100644 (file)
@@ -1,3 +1,9 @@
+2011-07-08  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49673
+       * typeck.c (cp_apply_type_quals_to_decl): Don't check
+       TYPE_NEEDS_CONSTRUCTING.
+
 2011-07-07  Jason Merrill  <jason@redhat.com>
 
        PR c++/49663
index 2acb18efbaed11b2e14631379fc829ba4d7d0397..f0d68c3dca58b7e31b1fc4a36e18f9fb225f4771 100644 (file)
@@ -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))
index 360c0aae53d7cbb5ab4b9d623b2ec66e1afe2e5b..9393815eab77d3108d5c1a67cfee08d602e62656 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-08  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49673
+       * g++.dg/cpp0x/constexpr-rom.C: New.
+
 2011-07-08  Kirill Yukhin  <kirill.yukhin@intel.com>
 
        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 (file)
index 0000000..e2edb2e
--- /dev/null
@@ -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 };