From 6d876e0b31aab2bf03e93b1d4705330f20f2c656 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 20 Jul 2012 02:29:13 -0400 Subject: [PATCH] re PR c++/54026 (template const struct with mutable members erroneously emitted to .rodata) PR c++/54026 * typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P. From-SVN: r189701 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/typeck.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/init/mutable1.C | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/mutable1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 649b6561ca8..647b719c734 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2012-07-19 Jason Merrill + 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. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 508e8fb25bc..d7a719fcf44 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/ChangeLog b/gcc/testsuite/ChangeLog index 25891a8cf27..8ae7ff8f3c9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-07-19 Jason Merrill + + PR c++/54026 + * g++.dg/init/mutable1.C: New. + 2012-07-20 Tobias Burnus 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 index 00000000000..af99ee0bf86 --- /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 +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 foo = { 1, 2 }; +const Bar bar = { 3, 4 }; -- 2.30.2