behaviour of typeof () changed
Jan Nieuwenhuizen
janneke@gnu.org
Sat Aug 14 12:08:00 GMT 1999
Hi,
I'm not sure if it's a bug, but gcc-2.95's typeof () now respects
constness. This may seem right, but it's different from gcc-2.8
and egcs-1.1.2. In particular, it breaks the use of macros for
simple clone () functionality.
In this example, typeof (*this) returns 'class A const*', and
it seems that this constness cannot be cast/tricked away.
LilyPond makes heavy use of the former typeof () functionlity.
Help.
Greetings,
Jan
clone.cc:
/*
20:27:46 appel ~/usr/src/c++$ g++ --version
2.95
20:28:02 appel ~/usr/src/c++$ uname -a
Linux appel.flower 2.2.6-15apmac #1 Fri Apr 30 12:52:03 EDT 1999 ppc unknown
20:28:06 appel ~/usr/src/c++$ make clone
g++ clone.cc -o clone
clone.cc: In method `class A * A::clone() const':
clone.cc:25: return to `A *' from `const A *' discards qualifiers
make: *** [clone] Error 1
*/
#include <stdio.h>
#define VIRTUAL_COPY_CONS(base) \
virtual base* clone () const \
{ \
return new typeof(*this) (*this); \
}
class A
{
public:
VIRTUAL_COPY_CONS (A);
virtual void print () { puts ("A"); }
};
int
main ()
{
A a;
A* b = a.clone ();
return 0;
}
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien/ | http://www.lilypond.org/
More information about the Gcc-bugs
mailing list