From: jason Date: Fri, 20 Jul 2012 06:29:33 +0000 (+0000) Subject: PR c++/54026 X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=1203564591145ea4275d6ba66b6a35501bad130f PR c++/54026 * typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@189702 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d567568b68f..8560c88a6ea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2012-07-19 Jason Merrill + + PR c++/54026 + * typeck.c (cp_apply_type_quals_to_decl): Check COMPLETE_TYPE_P. + 2012-07-18 Jason Merrill * method.c (process_subob_fn): Make sure no_implicit_p is non-null diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 76fc58565da..96b7d4e4419 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8296,9 +8296,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 5615b74c6f6..efaf1dc6f57 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-19 Eric Botcazou * gnat.dg/opt25.adb: New test. 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 };