Commit 9482b620 by Marek Polacek Committed by Marek Polacek

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
parent 0b98bb4e
2015-06-04 Marek Polacek <polacek@redhat.com>
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 <prathamesh.kulkarni@linaro.org>
* c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc.
......
......@@ -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
......
2015-06-04 Marek Polacek <polacek@redhat.com>
PR c/66341
* gcc.dg/lvalue-8.c: New test.
2015-06-03 Manuel López-Ibáñez <manu@gcc.gnu.org>
Paolo Carlini <paolo.carlini@oracle.com>
......
/* 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" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment