This is the mail archive of the gcc@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




Sometime in the late 1900s it was said:

OK.  I may be in the dark here too.  But afaik const_cast<T>( t )
will cast t to T exactly as  (T)t  would have iff T and the type
of t are different either in 'const' and 'volatile'.  At least that
is what Bjarne Stroustrup confirms (as I paraphrased from his book).

Am I wrong?


Regards,

patrick@boxsoft.com


> Please pardon my ignorance here but I'm not sure I understand what the
> issue is. For const_cast, the return type for a cast from anything other
> than a reference type is an rvalue. In this case I would expect your
> code to execute the default constructor then call your copy constructor.
> Your cast doesn't have any effect that I can see. Is this not the
> behaviour you're getting or anticipate?
> 
> 	later,
> 
> 		Ben Scherrey
> 
> Gabriel Dos_Reis wrote:
> > 
> > EGCS/g++ happily accepts to const_cast to rvalues of class type.
> > 
> > // --- cut here ---
> > #include <iostream>
> > 
> > struct A {
> >   A() {}
> >   A(const A&) { std::cout << "A::A(const A&)\n"; }
> > };
> > 
> > int main()
> > {
> >   A a;
> >   const_cast<const A>(a);       // ERROR
> > }
> > // --- cut here ---
> > 
> > The program is ill-formed according to 5.2.11.


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