This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Ping: PATCH to generate error for address of cast


I sent this patch out a week or so ago, and it hasn't been reviewed.
Sending it again...

And as long as I was resending the patch anyway, I've also written
a couple of test cases for it: one to make sure that I didn't break
the cast-as-lvalue extension, one to verify that the patch does what
I claim, and generates an error message when you try to take the
address of a cast. Sorry, I don't know how to get 'cvs diff' to include
new files when I don't have write access to the repository, so I'm
just appending those two files on their own.

(By the way, you might be wondering why I'm doing all this
complicated stuff instead of just fixing lvalue_or_else. Answer:
I found that changing lvalue_or_else breaks the case-as-lvalue
extension in a couple places. Having a regression test suite is
nice.)

--Matt


Index: gcc/cp/typeck.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.421
diff -u -r1.421 typeck.c
--- gcc/cp/typeck.c 9 Aug 2002 19:57:01 -0000 1.421
+++ gcc/cp/typeck.c 14 Aug 2002 17:25:58 -0000
@@ -4237,8 +4237,14 @@
is an error. */
else if (TREE_CODE (argtype) != FUNCTION_TYPE
&& TREE_CODE (argtype) != METHOD_TYPE
- && !lvalue_or_else (arg, "unary `&'"))
- return error_mark_node;
+ && (!lvalue_p (arg) ||
+ (TREE_CODE (arg) == NOP_EXPR &&
+ !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg)),
+ TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)))))))
+ {
+ error ("non-lvalue in unary `&'");
+ return error_mark_node;
+ }

if (argtype != error_mark_node)
argtype = build_pointer_type (argtype);




========================================
bash-2.05$ cat gcc/testsuite/g++.dg/expr/lvaddr.C
// Copyright (C) 2002 Free Software Foundation
// Contributed by Matt Austern <austern@apple.com>

// { dg-do compile }

void f()
{
int n;
char* p = &(char) n; // { dg-error "non-lvalue" }
}



========================================
bash-2.05$ cat gcc/testsuite/g++.dg/expr/lvcast.C
// Copyright (C) 2002 Free Software Foundation
// Contributed by Matt Austern <austern@apple.com>

// { dg-do compile }

void f()
{
int n;
static_cast<char>(n) = 0;
(char) n = 1;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]