Does an assignment operator in c++ return rvalue or lvalue?
Asked Answered
S

1

7

Does an assignment operator in c++ returns an rvalue or an lvalue? And if it is an lvalue, which of the two arguments will be incremented here?

(a = b)++
Syphilology answered 8/10, 2013 at 9:59 Comment(2)
Have you tried it? A simple debug message should tell you the answer.Ania
It works, and it returns lvalue for first argument, but maybe it's undefined or unspecified behavior? Or maybe works only for this case?Brezhnev
C
11

It returns a lvalue. Per § 5.17:

The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand.

If those objects have an user-defined operator for assignment, then it depends on implementation and declaration (return type) of the operator=.

So normally, after

(a = b)++

The object a will be incremented.

Cordwood answered 8/10, 2013 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.