What is the value category of the operands of C++ operators when unspecified?

前端 未结 1 676
情深已故
情深已故 2020-11-27 07:46

PREMISE:

The C++11 Standard classifies expressions into three disjoint value categories: lvalues, xvalues, and

相关标签:
1条回答
  • 2020-11-27 08:24

    Yes, it's ill-specified and has been covered before. Basically, every time an lvalue expression is required is enumerated, so we assume that every other operand must be a prvalue expression.

    So to answer your questions:

    1. A prvalue.
    2. If it's not specified, it's a prvalue.

    The note that is quoted in the linked answer seems to have changed a few times. The quote from §3.10 of the C++11 standard is as follows (and at the current time is identical in the latest draft):

    [ Note: The discussion of each built-in operator in Clause 5 indicates the category of the value it yields and the value categories of the operands it expects. For example, the built-in assignment operators expect that the left operand is an lvalue and that the right operand is a prvalue and yield an lvalue as the result. User-defined operators are functions, and the categories of values they expect and yield are determined by their parameter and return types. — end note ]

    Here it even says explicitly that the assignment operators expect the right operand to be a prvalue. Of course, this is a note and is therefore non-normative.

    0 讨论(0)
提交回复
热议问题