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
This commit is contained in:
Nathan Sidwell 2001-12-29 17:10:10 +00:00 committed by Nathan Sidwell
parent 1bf0567179
commit 03c9c27462
5 changed files with 42 additions and 12 deletions

View File

@ -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>

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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.

View File

@ -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" "" }
}