]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/54026 (template const struct with mutable members erroneously emitted to...
authorJason Merrill <jason@redhat.com>
Fri, 20 Jul 2012 06:29:13 +0000 (02:29 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 20 Jul 2012 06:29:13 +0000 (02:29 -0400)
PR c++/54026
* typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P.

From-SVN: r189701

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/mutable1.C [new file with mode: 0644]

index 649b6561ca8d5ade316d2657d22830ae35e8c5b7..647b719c734ec857af4676bc1e91be04270c89b5 100644 (file)
@@ -1,5 +1,8 @@
 2012-07-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/54026
+       * typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P.
+
        PR c++/54021
        * call.c (build_cxx_call): Set optimize when folding
        __builtin_constant_p in a constexpr function.
index 508e8fb25bc5166313f0387fdda072808b21d145..d7a719fcf44be5a874326324f4d056b8afd81d1e 100644 (file)
@@ -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);
index 25891a8cf2740172ca3248ede39bca9f1ae1b820..8ae7ff8f3c9f6c13cad4318a6ece568e2ea45b71 100644 (file)
@@ -1,3 +1,8 @@
+2012-07-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/54026
+       * g++.dg/init/mutable1.C: New.
+
 2012-07-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/48820
diff --git a/gcc/testsuite/g++.dg/init/mutable1.C b/gcc/testsuite/g++.dg/init/mutable1.C
new file mode 100644 (file)
index 0000000..af99ee0
--- /dev/null
@@ -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 };