are std::chrono literals lvalues?
No. std::chrono_literals
are prvalues.
Is this intended behaviour?
It is as the standard has specified.
These values are of class types. And rvalues of class types can be assigned1 as long as the class is assignable, and their assignment operator overload is not lvalue ref qualified. Assignment operators of classes, like all member functions, are not lvalue ref qualified by default, and hardly any standard class has such qualified overload2 - I don't know of any but if there are, std::chrono::duration
isn't one of them.
Note that the literal isn't modified. The left hand operand is a temporary object which in this case is discarded.
Another simple example of assigning an rvalue:
std::string{"temporary"} = "this is pointless, but legal";
1 This is actually a useful feature, although there aren't many use cases. Here is a useful example:
std::vector<bool> vec{true, false, true};
vec[1] = true; // vec[1] is an rvalue
2 Prior to C++11, there were no ref qualifiers, and thus all rvalues of assignable class types could be assigned. To maintain backward compatibility, the default cannot be changed, nor can pre-existing classes be changed (at least not without a deprecation period). std::chrono::duration
was added in C++11, so it could have had qualified assignment operator, but standard authors appear to prefer not qualifying their assignment operators.