#2240 ++a is not treated as an rvalue

open
nobody
None
Front-end
5
2014-09-23
2014-01-04
Maarten Brock
No

After a long discussion on the mailing list
https://sourceforge.net/p/sdcc/mailman/message/31801282/
this came out.

The following code should generate error 10: lvalue required:

char E=0, b=1;
++E = b;

as the spec says that ++E is equivalent to (E+=1) which is not an lvalue.

Discussion

  • Maarten Brock
    Maarten Brock
    2014-01-05

    After I made ++E an rvalue *++E started to fail. I believe this is wrong because * should turn an rvalue into an lvalue, right ? But this check in SDCCast.c line 3666 is already present from day 1 ?! Further I get the feeling most expressions are marked neither lvalue nor rvalue and slip through many tests.

    It might also be that I totally misunderstand the lvalue and rvalue fields and that they don't mark the AST to BE an lvalue/rvalue but to REQUIRE an lvalue/rvalue.

     
  • Maarten Brock
    Maarten Brock
    2014-01-05

    The same goes for (E++)[1] which fails in SDCCast.c line 3120 after my mod. But (p+1)[1] is still ok, because (p+1) is marked neither lvalue nor rvalue.

     
  • Maarten Brock
    Maarten Brock
    2014-01-05

    I really don't get it. In SDCCast.c lines 3229-3243 the operand of ++ or -- is marked lvalue, no matter if it really is one or not. IMO that is too late. It should check whether the operand is an lvalue instead. And IMO it should mark the ast as rvalue. Can anyone explain?