I think I may have come up with an example of rvalue of array type

后端 未结 2 1157
攒了一身酷
攒了一身酷 2020-12-16 00:52

C++03 §4.2 N°1:
An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer

2条回答
  •  粉色の甜心
    2020-12-16 01:20

    Yes, you are correct. The expression is an rvalue of array type. This is not a defect - the committee knows about it, and it was also a common issue in C89, which only allows conversion to pointers for lvalues of array types. As a consequence, you could not index or dereference an array like f().a. C99 fixed this, and C++ does not have a problem with it.

    Note that whether or not it is an rvalue is independent to whether or not the expression denotes an object. C++03 accidentally omitted to say that an rvalue expression that is of array type denotes an object. This was fixed in C++0x by DR#450.

    (obviously appreciating that there are no rvalues of such)

    There are actually rvalues of function types. These occur for non-static member functions denoted by a class member access expression

    struct A { void f(); };
    
    /* A().f is an rvalue of type "void()" */
    int main() { A().f(); }
    

提交回复
热议问题