Search code examples
c++language-lawyerconditional-operatorlvalue

What is the motivation to decline C rule "a conditional expression does not yield an lvalue"?


What is the motivation to decline C rule a conditional expression does not yield an lvalue?

In other words: in C it was a motivation (which exactly?) to not yield an lvalue. Why in C++ this motivation was declined (or reconsidered)?


Solution

  • C++ has references; C does not.

    You wouldn't be able to bind [mutable] references from an invocation of the conditional operator if not for the following rule:

    [expr.cond/5]: If the second and third operands are glvalues of the same value category and have the same type, the result is of that type and value category and it is a bit-field if the second or the third operand is a bit-field, or if both are bit-fields.