3.10 Lvalues and rvalues [basic.lval]

1 Every expression is either an lvalue or an rvalue.

2 An lvalue refers to an object or function. Some rvalue expressions—those of class or cv-qualified class type—also refer to objects. 47)

3 [Note:
some built-in operators and function calls yield lvalues. [Example: if E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the function
int& f();
yields an lvalue, so the call f() is an lvalue expression. ] ]

[注意：某些内置运算符以及一些函数调用会返回左值。[例1：如果 E 是一个指针类型的表达式，那么 *E 是一个左值表达式，指示指针 E 所指向的那个对象或者函数。例2：函数
int& f();

4 [Note: some built-in operators expect lvalue operands. [Example: built-in assignment operators all expect their left hand operands to be lvalues. ] Other built-in operators yield rvalues, and some expect them. [Example: the unary and binary + operators expect rvalue arguments and yield rvalue results. ] The discussion of each built-in operator in clause 5 indicates whether it expects lvalue operands and whether it yields an lvalue. ]

[注意：某些内置运算符需要左值操作数。[例：所有内置的赋值运算符的左操作数都必须是左值。] 有些内置运算符会返回右值结果，有些会需要右值操作数。[例：一元运算符“+”和二元运算符“+”都需要右值操作数，并且返回右值结果。] 我们在条款 5 中会对所有内置运算符进行讨论，指出它们的操作数和返回结果是左值还是右值。]

5 The result of calling a function that does not return a reference is an rvalue. User defined operators are functions, and whether such operators expect or yield lvalues is determined by their parameter and return
types.

6 An expression which holds a temporary object resulting from a cast to a nonreference type is an rvalue (this includes the explicit creation of an object using functional notation (5.2.3)).

__________________
47) Expressions such as invocations of constructors and of functions that return a class type refer to objects, and the implementation can invoke a member function upon such objects, but the expressions are not lvalues.

____________________________________华丽的分页符____________________________________

7 Whenever an lvalue appears in a context where an rvalue is expected, the lvalue is converted to an rvalue; see 4.1, 4.2, and 4.3.

8 The discussion of reference initialization in 8.5.3 and of temporaries in 12.2 indicates the behavior of lvalues and rvalues in other significant contexts.

12.2 中关于引用的初始化和关于临时对象的讨论，也指出了左右值在其他重要场合的行为。

9 Class rvalues can have cv-qualified types; non-class rvalues always have cv-unqualified types. Rvalues shall always have complete types or the void type; in addition to these types, lvalues can also have incomplete types.

10 An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can also be used to modify its referent under certain circumstances. [Example: a member function called for an object (9.3) can modify the object. ]

11 Functions cannot be modified, but pointers to functions can be modifiable.

12 A pointer to an incomplete type can be modifiable. At some point in the program when the pointed to type is complete, the object at which the pointer points can also be modified.

13 The referent of a const-qualified expression shall not be modified (through that expression), except that if it is of class type and has a mutable component, that component can be modified (7.1.5.1).

14 If an expression can be used to modify the object to which it refers, the expression is called modifiable. A program that attempts to modify an object through a nonmodifiable lvalue or rvalue expression is illformed.

15 If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behavior is undefined 48):
— the dynamic type of the object,
— a cv-qualified version of the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of
the object,
— an aggregate or union type that includes one of the aforementioned types among its members (including,
recursively, a member of a subaggregate or contained union),
— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
— a char or unsigned char type.

——对象的动态类型；
——CV 限定的对象动态类型；
——对象的动态类型对应的有符号或无符号类型；
——CV 限定的对象动态类型有符号或无符号类型；
——一个成员中含有聚合或者联合类型的聚合或者联合类型（包括递归形式的定义以及成员中有子聚合类型或者包含一个联合）
——对象的动态类型的基类类型（可以被 cv 限定符修饰）
——char 或 unsigned char 类型

__________________
48) The intent of this list is to specify those circumstances in which an object may or may not be aliased.

____________________________________华丽的分隔符____________________________________

posted on 2012-02-29 22:50 溪流 阅读(1538) 评论(0)  编辑 收藏 引用 所属分类: C++

 只有注册用户登录后才能发表评论。 相关文章: