FunkyBaby
FunkyBaby

Reputation: 565

Why bool conversion explicitly mentions prvalue

In 4.14 http://eel.is/c++draft/conv.bool#1

It says:

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool.

Why specifically emphasize prvalue?

lvalue of arithmetic type can also be converted to bool.

Upvotes: 1

Views: 126

Answers (1)

The standard doesn't want a boolean conversion to affect lvalues, so it does not allow it.

You can of course convert an lvalue of arithmetic type to type bool, but it is not done through (just) a boolean conversion. Converting an arithmetic lvalue into a bool is a standard conversion sequence consisting of an lvalue-to-rvalue conversion followed by a boolean conversion.

Upvotes: 1

Related Questions