This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch reversion request
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org, Matt Austern <austern at apple dot com>, mark at codesourcery dot com, jason at redhat dot com
- Date: Thu, 12 Sep 2002 19:43:08 +0100
- Subject: patch reversion request
- Organization: Codesourcery LLC
Hi,
The attached patch breaks the following well formed C++,
void baz (const long &)
void foo (int a)
{
baz((long)a);
}
which is a regresion. see gnats prs 7828 & 7858
There appears to be no activity to fix this regression, Matt's patch
fixes a case where we allowed ill-formed code. I request that the patch
be reverted.
nathan
--
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
2002-08-24 Matt Austern <austern@apple.com>
* tree.c (lvalue_p_1): Add argument for whether casts of lvalues
are allowable.
(real_lvalue_p): Update caller.
(lvalue_p): Ditto.
(non_cast_lvalue_or_else): New.
* tree.h: Declare it.
* typeck.c (build_unary_op): Use non_cast_lvalue_or_else.
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.295
retrieving revision 1.296
diff -c -3 -p -r1.295 -r1.296
*** tree.c 11 Aug 2002 16:05:27 -0000 1.295
--- tree.c 25 Aug 2002 04:57:15 -0000 1.296
*************** static tree build_cplus_array_type_1 PAR
*** 39,45 ****
static int list_hash_eq PARAMS ((const void *, const void *));
static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
static hashval_t list_hash PARAMS ((const void *));
! static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int));
static tree no_linkage_helper PARAMS ((tree *, int *, void *));
static tree build_srcloc PARAMS ((const char *, int));
static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
--- 39,45 ----
static int list_hash_eq PARAMS ((const void *, const void *));
static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
static hashval_t list_hash PARAMS ((const void *));
! static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int, int));
static tree no_linkage_helper PARAMS ((tree *, int *, void *));
static tree build_srcloc PARAMS ((const char *, int));
static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
*************** static tree handle_init_priority_attribu
*** 59,67 ****
non-zero, rvalues of class type are considered lvalues. */
static cp_lvalue_kind
! lvalue_p_1 (ref, treat_class_rvalues_as_lvalues)
tree ref;
int treat_class_rvalues_as_lvalues;
{
cp_lvalue_kind op1_lvalue_kind = clk_none;
cp_lvalue_kind op2_lvalue_kind = clk_none;
--- 59,68 ----
non-zero, rvalues of class type are considered lvalues. */
static cp_lvalue_kind
! lvalue_p_1 (ref, treat_class_rvalues_as_lvalues, allow_cast_as_lvalue)
tree ref;
int treat_class_rvalues_as_lvalues;
+ int allow_cast_as_lvalue;
{
cp_lvalue_kind op1_lvalue_kind = clk_none;
cp_lvalue_kind op2_lvalue_kind = clk_none;
*************** lvalue_p_1 (ref, treat_class_rvalues_as_
*** 84,99 ****
case WITH_CLEANUP_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
- /* This shouldn't be here, but there are lots of places in the compiler
- that are sloppy about tacking on NOP_EXPRs to the same type when
- no actual conversion is happening. */
- case NOP_EXPR:
return lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues);
case COMPONENT_REF:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues);
if (op1_lvalue_kind
/* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
situations. */
--- 85,112 ----
case WITH_CLEANUP_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
return lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
!
! case NOP_EXPR:
! /* If expression doesn't change the type, we consider it as an
! lvalue even when cast_as_lvalue extension isn't selected.
! That's because parts of the compiler are alleged to be sloppy
! about sticking in NOP_EXPR node for no good reason. */
! if (allow_cast_as_lvalue ||
! same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ref)),
! TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (ref, 0)))))
! return lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
! else
! return clk_none;
case COMPONENT_REF:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
if (op1_lvalue_kind
/* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
situations. */
*************** lvalue_p_1 (ref, treat_class_rvalues_as_
*** 134,149 ****
case MAX_EXPR:
case MIN_EXPR:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues);
op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues);
break;
case COND_EXPR:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues);
op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
! treat_class_rvalues_as_lvalues);
break;
case MODIFY_EXPR:
--- 147,166 ----
case MAX_EXPR:
case MIN_EXPR:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
break;
case COND_EXPR:
op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
break;
case MODIFY_EXPR:
*************** lvalue_p_1 (ref, treat_class_rvalues_as_
*** 151,157 ****
case COMPOUND_EXPR:
return lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues);
case TARGET_EXPR:
return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
--- 168,175 ----
case COMPOUND_EXPR:
return lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues,
! allow_cast_as_lvalue);
case TARGET_EXPR:
return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
*************** cp_lvalue_kind
*** 196,202 ****
real_lvalue_p (ref)
tree ref;
{
! return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0);
}
/* This differs from real_lvalue_p in that class rvalues are
--- 214,220 ----
real_lvalue_p (ref)
tree ref;
{
! return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/ 0, /*cast*/ 1);
}
/* This differs from real_lvalue_p in that class rvalues are
*************** lvalue_p (ref)
*** 207,213 ****
tree ref;
{
return
! (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none);
}
/* Return nonzero if REF is an lvalue valid for this language;
--- 225,231 ----
tree ref;
{
return
! (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 1) != clk_none);
}
/* Return nonzero if REF is an lvalue valid for this language;
*************** lvalue_or_else (ref, string)
*** 218,224 ****
tree ref;
const char *string;
{
! int win = lvalue_p (ref);
if (! win)
error ("non-lvalue in %s", string);
return win;
--- 236,255 ----
tree ref;
const char *string;
{
! int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 1);
! int win = (ret != clk_none);
! if (! win)
! error ("non-lvalue in %s", string);
! return win;
! }
!
! int
! non_cast_lvalue_or_else (ref, string)
! tree ref;
! const char *string;
! {
! int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 0);
! int win = (ret != clk_none);
if (! win)
error ("non-lvalue in %s", string);
return win;
Index: typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.424
retrieving revision 1.425
diff -c -3 -p -r1.424 -r1.425
*** typeck.c 23 Aug 2002 00:28:29 -0000 1.424
--- typeck.c 25 Aug 2002 04:57:15 -0000 1.425
*************** build_unary_op (code, xarg, noconvert)
*** 4268,4274 ****
is an error. */
else if (TREE_CODE (argtype) != FUNCTION_TYPE
&& TREE_CODE (argtype) != METHOD_TYPE
! && !lvalue_or_else (arg, "unary `&'"))
return error_mark_node;
if (argtype != error_mark_node)
--- 4268,4274 ----
is an error. */
else if (TREE_CODE (argtype) != FUNCTION_TYPE
&& TREE_CODE (argtype) != METHOD_TYPE
! && !non_cast_lvalue_or_else (arg, "unary `&'"))
return error_mark_node;
if (argtype != error_mark_node)