[C++ PATCH]: Fix 335
Nathan Sidwell
nathan@codesourcery.com
Thu Dec 27 12:44:00 GMT 2001
Hi,
this fixes bug 335 where we silently allowed a read only member to be
modified. resolve_offset_ref was not propagating the cv quals of *this.
I also simplified require_complete_type, by using resolve_offset_ref.
built & tested on i686-pc-linux-gnu, ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
-------------- next part --------------
2001-12-26 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).
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.259
diff -c -3 -p -r1.259 init.c
*** init.c 2001/12/18 09:36:02 1.259
--- init.c 2001/12/26 18:45:19
*************** resolve_offset_ref (exp)
*** 1840,1847 ****
if (expr == error_mark_node)
return error_mark_node;
! expr = build (COMPONENT_REF, TREE_TYPE (member),
! expr, member);
return convert_from_reference (expr);
}
--- 1840,1857 ----
if (expr == error_mark_node)
return error_mark_node;
! 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);
}
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.378
diff -c -3 -p -r1.378 typeck.c
*** typeck.c 2001/12/24 20:52:36 1.378
--- typeck.c 2001/12/26 18:53:30
*************** require_complete_type (value)
*** 114,128 ****
&& 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);
return require_complete_type (value);
}
--- 114,120 ----
&& current_class_ref != 0
&& TREE_OPERAND (value, 0) == current_class_ref)
{
! value = resolve_offset_ref (value);
return require_complete_type (value);
}
-------------- next part --------------
// { 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" "" }
}
More information about the Gcc-patches
mailing list