This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15580] New: wrong code generation in c++ assignment operator
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 May 2004 23:45:56 -0000
- Subject: [Bug c++/15580] New: wrong code generation in c++ assignment operator
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
`this' calculated incorrectly for the assignment operator of the virtual base.
Environment:
gcc 3.3.x
How-To-Repeat:
[8<---test.cc---]
struct A { int a; };
struct B : virtual A { };
struct C : virtual A { };
struct D : B, C { };
int
main()
{
D d;
d = d;
d.a = 5;
}
[--->8]
g++ test.cc
./a.out
no optimization should be used, otherwise `d.a' reference will be cached
from assignment operation. in any doubt this is an optimizer error here
is a modified version of the same test.cc which will crash in any of -Oxx
switches:
[...]
void test(D d);
int
main()
{
D d;
d = d;
test(d);
}
void test(D d)
{
}
>Workaround:
downgrade to 3.2.x
------- Additional Comments From unicorn at re dot com dot ua 2004-05-21 23:45 -------
Fix:
downgrade to 3.2.x
- or -
here is a patch for gcc version 3.3.3 [FreeBSD] 20031106:
Index: method.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/cp/method.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 method.c
--- method.c 22 Aug 2003 02:56:03 -0000 1.1.1.10
+++ method.c 21 May 2004 04:52:33 -0000
@@ -665,15 +665,17 @@
for (i = 0; i < CLASSTYPE_N_BASECLASSES (current_class_type); ++i)
{
tree binfo;
+ tree dst;
tree converted_parm;
binfo = BINFO_BASETYPE (TYPE_BINFO (current_class_type), i);
/* We must convert PARM directly to the base class
explicitly since the base class may be ambiguous. */
converted_parm = build_base_path (PLUS_EXPR, parm, binfo, 1);
+ dst = build_base_path (PLUS_EXPR, current_class_ref, binfo, 1);
/* Call the base class assignment operator. */
finish_expr_stmt
- (build_special_member_call (current_class_ref,
+ (build_special_member_call (dst,
ansi_assopname (NOP_EXPR),
build_tree_list (NULL_TREE,
converted_parm),
--
Summary: wrong code generation in c++ assignment operator
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: unicorn at re dot com dot ua
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15580