This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Don't accept a cast as a valid LHS (PR c/66341)
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 3 Jun 2015 18:02:12 +0000
- Subject: Re: [C PATCH] Don't accept a cast as a valid LHS (PR c/66341)
- Authentication-results: sourceware.org; auth=none
- References: <20150603173222 dot GJ2756 at redhat dot com>
On Wed, 3 Jun 2015, Marek Polacek wrote:
> Since a cast does not yield an lvalue, we shouldn't accept invalid
> code as in the attached testcase.
>
> The problem was that we weren't setting NON_LVALUE_EXPR properly;
> for comparing expressions we shouldn't use ==, because then a cast
> in an expression might confuse us.
I'm not clear on what trees you get in the problem case (or which of the
tests in the testcase you added was broken before - they don't seem that
similar to the tests in the bug). It would seem safer to me to use
lvalue_p (value) as the condition for adding a NON_VALUE_EXPR.
> + /* A cast to a qualified type has the same effect as a cast
> + to the unqualified version of the type. */
> + (const int *) p = 0; /* { dg-error "lvalue required as left operand of assignment" } */
That's not a cast to a qualified type. A cast to qualified type would be
(int *const) p.
--
Joseph S. Myers
joseph@codesourcery.com