This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/57155] casting to const reference error


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57155

--- Comment #2 from rockeet <rockeet at gmail dot com> 2013-05-03 10:35:53 UTC ---
In this case, C++ shouldn't create a temporal object and bound the const ref to
it. The C++ standard (C++11) says:

5.2.1
Subscripting
[expr.sub]
1
A postfix expression followed by an expression in square brackets is a postfix
expression. One of the expres-
sions shall have the type âpointer to Tâ and the other shall have unscoped
enumeration or integral type.
The result is an lvalue of type âT.â The type âTâ shall be a completely-defined
object type.61The expression
E1[E2] is identical (by definition) to *((E1)+(E2)) [Note: see 5.3 and 5.7 for
details of * and + and 8.3.4
for details of arrays. âend note ]

5.3.1
Unary operators
[expr.unary.op]
1
The unary * operator performs indirection: the expression to which it is
applied shall be a pointer to an
object type, or a pointer to a function type and the result is an lvalue
referring to the object or function
to which the expression points. If the type of the expression is âpointer to
T,â the type of the result is âT.â
[Note: a pointer to an incomplete type (other than cv void) can be
dereferenced. The lvalue thus obtained
can be used in limited ways (to initialize a reference, for example); this
lvalue must not be converted to a
prvalue, see 4.1. âend note ]

5.4
Explicit type conversion (cast notation)
[expr.cast]
1
The result of the expression (T) cast-expression is of type T. The result is an
lvalue if T is an lvalue reference
type or an rvalue reference to function type and an xvalue if T is an rvalue
reference to object type; otherwise
the result is a prvalue. [Note: if T is a non-class type that is cv-qualified,
the cv-qualifiers are ignored when
determining the type of the resulting prvalue; see 3.10. âend note ]

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]