diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2001-12-29 17:10:10 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2001-12-29 17:10:10 +0000 |
commit | 03c9c274624a94356dffd1cd62ff9669a8a1039a (patch) | |
tree | d6c3ce64a187a221e478142f0138060f138530c8 | |
parent | 1bf0567179b2828650b21eced842742526039651 (diff) | |
download | gcc-03c9c274624a94356dffd1cd62ff9669a8a1039a.zip gcc-03c9c274624a94356dffd1cd62ff9669a8a1039a.tar.gz gcc-03c9c274624a94356dffd1cd62ff9669a8a1039a.tar.bz2 |
re PR c++/335 (gcc accepts assignment in read-only structures)
cp:
PR c++/335
* init.c (resolve_offset_ref): Copy cv qualifiers of this pointer
for non-reference fields.
* typeck.c (require_complete_type): Use resolve_offset_ref).
testsuite:
* g++.dg/other/const1.C: New test.
From-SVN: r48369
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/init.c | 14 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/const1.C | 17 |
5 files changed, 42 insertions, 12 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fc7a609..77d4c5d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,7 +1,14 @@ +2001-12-29 Nathan Sidwell <nathan@codesourcery.com> + + PR c++/335 + * init.c (resolve_offset_ref): Copy cv qualifiers of this pointer + for non-reference fields. + * typeck.c (require_complete_type): Use resolve_offset_ref). + 2001-12-26 Nathan Sidwell <nathan@codesourcery.com> PR c++/196 - * cp/parse.y (bad_parm): Better diagnostic when given a SCOPE_REF. + * parse.y (bad_parm): Better diagnostic when given a SCOPE_REF. 2001-12-24 Nathan Sidwell <nathan@codesourcery.com> diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 54bb076..f159f44 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1840,8 +1840,18 @@ resolve_offset_ref (exp) if (expr == error_mark_node) return error_mark_node; - expr = build (COMPONENT_REF, TREE_TYPE (member), - expr, member); + type = TREE_TYPE (member); + if (TREE_CODE (type) != REFERENCE_TYPE) + { + int quals = cp_type_quals (type) | cp_type_quals (TREE_TYPE (expr)); + + if (DECL_MUTABLE_P (member)) + quals &= ~TYPE_QUAL_CONST; + + type = cp_build_qualified_type (type, quals); + } + + expr = build (COMPONENT_REF, type, expr, member); return convert_from_reference (expr); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index fefa72e..1ad9de2 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -114,15 +114,7 @@ require_complete_type (value) && current_class_ref != 0 && TREE_OPERAND (value, 0) == current_class_ref) { - tree base, member = TREE_OPERAND (value, 1); - tree basetype = TYPE_OFFSET_BASETYPE (type); - - my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305); - basetype = lookup_base (current_class_type, basetype, ba_check, NULL); - base = build_base_path (PLUS_EXPR, current_class_ptr, basetype, 1); - - value = build (COMPONENT_REF, TREE_TYPE (member), - build_indirect_ref (base, NULL), member); + value = resolve_offset_ref (value); return require_complete_type (value); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 79c12d5..89cf025 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-12-29 Nathan Sidwell <nathan@codesourcery.com> + + * g++.dg/other/const1.C: New test. + 2001-12-29 Hans-Peter Nilsson <hp@bitrange.com> * gcc.c-torture/compile/20011229-1.c: New test. diff --git a/gcc/testsuite/g++.dg/other/const1.C b/gcc/testsuite/g++.dg/other/const1.C new file mode 100644 index 0000000..1d5450a --- /dev/null +++ b/gcc/testsuite/g++.dg/other/const1.C @@ -0,0 +1,17 @@ +// { dg-do compile } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@nathan@codesourcery.com> + +// PR 335. Missed diagnostic + +struct Foo +{ + unsigned i; + void Modify(unsigned j) const; +}; + +void Foo::Modify(unsigned j) const +{ + Foo::i = j; // { dg-error "assignment of data-member" "" } +} |