This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Fix build_component_ref damage
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 22 Aug 2002 17:22:36 -0700
- Subject: C++ PATCH: Fix build_component_ref damage
- Reply-to: mark at codesourcery dot com
Jason found one problem with my build_component_ref elimination and
Graham another. Here are the fixes.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-08-22 Mark Mitchell <mark@codesourcery.com>
* typeck.c (build_class_member_access_expr): Handle COMPOUND_EXPR
and COND_EXPR specially; fix error message output.
2002-08-22 Mark Mitchell <mark@codesourcery.com>
* testsuite/g++.dg/inherit/cond1.C: New test.
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.423
diff -c -p -r1.423 typeck.c
*** cp/typeck.c 17 Aug 2002 12:26:01 -0000 1.423
--- cp/typeck.c 22 Aug 2002 17:15:17 -0000
*************** build_class_member_access_expr (tree obj
*** 1859,1864 ****
--- 1859,1885 ----
my_friendly_assert (DECL_P (member) || BASELINK_P (member),
20020801);
+ /* Transform `(a, b).x' into `a, b.x' and `(a ? b : c).x' into
+ `a ? b.x : c.x'. These transformations should not really be
+ necessary, but they are. */
+ if (TREE_CODE (object) == COMPOUND_EXPR)
+ {
+ result = build_class_member_access_expr (TREE_OPERAND (object, 1),
+ member, access_path,
+ preserve_reference);
+ return build (COMPOUND_EXPR, TREE_TYPE (result),
+ TREE_OPERAND (object, 0), result);
+ }
+ else if (TREE_CODE (object) == COND_EXPR)
+ return (build_conditional_expr
+ (TREE_OPERAND (object, 0),
+ build_class_member_access_expr (TREE_OPERAND (object, 1),
+ member, access_path,
+ preserve_reference),
+ build_class_member_access_expr (TREE_OPERAND (object, 2),
+ member, access_path,
+ preserve_reference)));
+
/* [expr.ref]
The type of the first expression shall be "class object" (of a
*************** finish_class_member_access_expr (tree ob
*** 2135,2141 ****
if (TREE_CODE (scope) == NAMESPACE_DECL)
{
error ("`%D::%D' is not a member of `%T'",
! scope, member, object_type);
return error_mark_node;
}
--- 2156,2162 ----
if (TREE_CODE (scope) == NAMESPACE_DECL)
{
error ("`%D::%D' is not a member of `%T'",
! scope, name, object_type);
return error_mark_node;
}
Index: testsuite/g++.dg/inherit/cond1.C
===================================================================
RCS file: testsuite/g++.dg/inherit/cond1.C
diff -N testsuite/g++.dg/inherit/cond1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/inherit/cond1.C 22 Aug 2002 17:15:19 -0000
***************
*** 0 ****
--- 1,10 ----
+ // Origin: jason@redhat.com
+ // { dg-do compile }
+
+ struct A { A(); A(const A&); int i; };
+ struct B: public A { };
+
+ int f (bool b, A& ar, B& br)
+ {
+ return (b?ar:br).i;
+ }