So, I guess the check for COMPLETE_TYPE_P wasn't as unnecessary as I thought.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit be65733bbf94c76f4fec314c41937fd51e53c705
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jul 19 17:07:10 2012 -0400

    	PR c++/54026
    	* typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P.

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 508e8fb..d7a719f 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8453,9 +8453,9 @@ cp_apply_type_quals_to_decl (int type_quals, tree decl)
      constructor can produce constant init, so rely on cp_finish_decl to
      clear TREE_READONLY if the variable has non-constant init.  */
 
-  /* If the type has a mutable component, that component might be
-     modified.  */
-  if (TYPE_HAS_MUTABLE_P (type))
+  /* If the type has (or might have) a mutable component, that component
+     might be modified.  */
+  if (TYPE_HAS_MUTABLE_P (type) || !COMPLETE_TYPE_P (type))
     type_quals &= ~TYPE_QUAL_CONST;
 
   c_apply_type_quals_to_decl (type_quals, decl);
diff --git a/gcc/testsuite/g++.dg/init/mutable1.C b/gcc/testsuite/g++.dg/init/mutable1.C
new file mode 100644
index 0000000..af99ee0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/mutable1.C
@@ -0,0 +1,20 @@
+// PR c++/54026
+// { dg-final { scan-assembler-not "rodata" } }
+
+void non_const(int *);
+
+template <typename T>
+struct Foo {
+  T x;
+  mutable int y;
+  void func() const { non_const(&y); }
+};
+
+struct Bar {
+  int x;
+  mutable int y;
+  void func() const { non_const(&y); }
+};
+
+const Foo<int> foo = { 1, 2 };
+const Bar bar = { 3, 4 };

Reply via email to