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]

Re: [C++ dayly bug report] const_cast to rvalue of class type


Benjamin Scherrey <scherrey@switchco.com> writes:

| Hmmm... 5.2.11 part 1 does not appear to disallow this cast and part 4
| says that an lvalue of type T1 can be const_cast to an lvalue of type T2
| as long as a pointer to T1 can be converted to a pointer to T2. That
| would allow this conversion the way I read it. This lvalue rvalue stuff
| always gets me screwed up but that's how I read it. Now the limitation
| you're talking about is certainly true and explicitly stated for dynamic
| casts. If I'm wrong I'd really like to know why.

The last two sentences of 5.2.11/1 say:

---
  Conversions that can be performed explicitly using const_cast are
  listed below. No other conversion shall be performed explicitly
  using const_cast.
---

5.2.11/3 deals exclusively with pointers.

5.2.11/4 states exactly:

---
  An lvalue of type T1 can be explicitly converted to an lvalue of
  type T2 using the cast const_cast<T2&> (whete T1 and T2 are object
                                      ^
  types) if a pointer to T1 can be explicitly converted to the type
  pointer T2 using const_cast. The result of a reference const_cast
  refers to the original object.
---

Notice 'T2&' in the syntax.

the remaining of 5.2.11 doesn't mention any case where const_cast<T2>
is allowed when T2 is class type.


-- Gaby


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