Bug 32023 - Message for lvalues could be improved if the cast was used as a lvalue
Summary: Message for lvalues could be improved if the cast was used as a lvalue
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-05-21 15:29 UTC by Nickolay V. Shmyrev
Modified: 2021-09-28 08:51 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-09-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nickolay V. Shmyrev 2007-05-21 15:29:40 UTC
The following program doesn't compile due to invalid lvalue in increment. The most strange thing is that gcc somehow ignores type coercion

int main ()
{
int **a;
void **b;

*b++;            /* works fine */
*((void **)a)++; / gives error */

return 0;
}
Comment 1 Andreas Schwab 2007-05-21 15:45:19 UTC
A cast is not an lvalue.
Comment 2 Nickolay V. Shmyrev 2007-05-22 18:16:37 UTC
Ok, I understand it. Gcc dropped support for cast in lvalues. But can the message be more specific about the problem itself. It's really hard to understand the reason from the current one.
Comment 3 Andrew Pinski 2007-05-22 18:27:16 UTC
t.c:9: error: lvalue required as increment operand


I don't see what the problem is, the error message is clear, a lvalue is required for the increment operand.
Comment 4 Nickolay V. Shmyrev 2007-05-22 18:33:38 UTC
gcc can explain why ((void **)a) is not lvalue, it's really not that clear.
Comment 5 Andreas Schwab 2007-05-22 21:32:56 UTC
Because the standard says so?
Comment 6 Nickolay V. Shmyrev 2007-05-22 21:36:01 UTC
Ok, add a line:

"According to standard cast is not lvalue"

I'll be happy.
Comment 7 Andreas Schwab 2007-05-22 21:51:01 UTC
Everything is "according to the standard".  That's where C is defined.
Comment 8 Nickolay V. Shmyrev 2007-05-23 00:12:52 UTC
The point I'm trying to express is that it's useful for user to have more precise explanation.

gcc dropped a lot of features which weren't included in standard recently and thus many of us wondering why the code which compiled before doesn't compile now. It's fine for me to have strict compiler but it's also useful to get at least an idea what compiler doesn't like without reading whole standard.
Comment 9 Andrew Pinski 2007-05-23 00:27:25 UTC
(In reply to comment #8)
> gcc dropped a lot of features which weren't included in standard recently and
> thus many of us wondering why the code which compiled before doesn't compile
> now. It's fine for me to have strict compiler but it's also useful to get at
> least an idea what compiler doesn't like without reading whole standard.

And that is exactly why GCC has changes page to describe these changes.  Yes this specific change is documented on that page.
Comment 10 Manuel López-Ibáñez 2007-05-23 16:57:17 UTC
(In reply to comment #8)
> The point I'm trying to express is that it's useful for user to have more
> precise explanation.
> 

Would you be happy with something like?

t.c:9: error: lvalue required as increment operand
t.c:9: note: a cast is not a lvalue

Perhaps we could even pack it in a single line.

The feasibility of this depends on whether we can get this information when we emit the diagnostic. I think if someone wants to pursue it, it shouldn't be difficult. So why not keep it open? Low-hanging fruit like this is ideal for newbies.
Comment 11 Nickolay V. Shmyrev 2007-05-23 17:06:13 UTC
Exactly :) Thanks Manuel
Comment 12 Andrew Pinski 2021-09-28 08:51:12 UTC
Clang gives a decent error message:

<source>:7:3: error: assignment to cast is illegal, lvalue casts are not supported
*((void **)a)++; /* gives error */
 ~^~~~~~~~~~~~~