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

Gabriel Dos_Reis Gabriel.Dos_Reis@sophia.inria.fr
Thu Apr 29 17:29:00 GMT 1999


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.

-- Gaby



More information about the Gcc-bugs mailing list