Skip to content

Incorrect C value category parsing #1251

@Suzukaze7

Description

@Suzukaze7

Some value category parsing logic is different from cppreference.

For example, assignment operators and comma operators are prvalue.

Non-lvalue object expressions

The following expressions are non-lvalue object expressions:

  • integer, character, and floating constants
  • all operators not specified to return lvalues, including
    • any function call expression
    • any cast expression (note that compound literals, which look similar, are lvalues)
    • member access operator (dot) applied to a non-lvalue structure/union, f().x, (x, s1).a, (s1 = s2).m
    • results of all arithmetic, relational, logical, and bitwise operators
    • results of increment and decrement operators (note: pre-forms are lvalues in C++)
    • results of assignment operators (note: also lvalues in C++)
    • the conditional operator (note: is lvalue in C++ if both the second and third operands are lvalues of the same type)
    • the comma operator (note: is lvalue in C++ if the second operand is)
    • the address-of operator, even if neutralized by application to the result of unary * operator

But in cdt, they are lvalue or conditional lvalue.

public boolean isLValue() {
switch (getOperator()) {
case op_assign:
case op_binaryAndAssign:
case op_binaryOrAssign:
case op_binaryXorAssign:
case op_divideAssign:
case op_minusAssign:
case op_moduloAssign:
case op_multiplyAssign:
case op_plusAssign:
case op_shiftLeftAssign:
case op_shiftRightAssign:
return true;
}
return false;
}

@Override
public boolean isLValue() {
for (int i = expressions.length - 1; i >= 0; i--) {
IASTExpression expr = expressions[i];
if (expr != null)
return expr.isLValue();
}
return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions