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; }
A cast is not an lvalue.
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.
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.
gcc can explain why ((void **)a) is not lvalue, it's really not that clear.
Because the standard says so?
Ok, add a line: "According to standard cast is not lvalue" I'll be happy.
Everything is "according to the standard". That's where C is defined.
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.
(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.
(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.
Exactly :) Thanks Manuel
Clang gives a decent error message: <source>:7:3: error: assignment to cast is illegal, lvalue casts are not supported *((void **)a)++; /* gives error */ ~^~~~~~~~~~~~~