From 9482b620d208237366e9d052918757cc5c17f519 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 4 Jun 2015 08:17:45 +0000 Subject: re PR c/66341 (Some casts wrongly produce a lvalue) PR c/66341 * c-typeck.c (build_c_cast): Wrap VALUE into NON_LVALUE_EXPR if it is a lvalue. * gcc.dg/lvalue-8.c: New test. From-SVN: r224115 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/lvalue-8.c | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/lvalue-8.c (limited to 'gcc') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 69344bb..d6be87f 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-06-04 Marek Polacek + + PR c/66341 + * c-typeck.c (build_c_cast): Wrap VALUE into NON_LVALUE_EXPR if + it is a lvalue. + 2015-06-03 Prathamesh Kulkarni * c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f55d4c6..6b313f3 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -5195,7 +5195,7 @@ build_c_cast (location_t loc, tree type, tree expr) } /* Don't let a cast be an lvalue. */ - if (value == expr) + if (lvalue_p (value)) value = non_lvalue_loc (loc, value); /* Don't allow the results of casting to floating-point or complex diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a74be77..3092acf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-04 Marek Polacek + + PR c/66341 + * gcc.dg/lvalue-8.c: New test. + 2015-06-03 Manuel López-Ibáñez Paolo Carlini diff --git a/gcc/testsuite/gcc.dg/lvalue-8.c b/gcc/testsuite/gcc.dg/lvalue-8.c new file mode 100644 index 0000000..04eeb71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lvalue-8.c @@ -0,0 +1,19 @@ +/* PR c/66341 */ +/* { dg-do compile } */ + +void +foo (int *p) +{ + p = 0; + /* A cast does not yield an lvalue. */ + (int *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + /* A cast to a qualified type has the same effect as a cast + to the unqualified version of the type. */ + (int *const) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (char *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (char *) (int *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (char *) (int *) (char *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (double *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (int *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ + (int *) (int *const) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */ +} -- cgit v1.1