This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
behaviour of typeof () changed
- To: gcc-bugs at gcc dot gnu dot org
- Subject: behaviour of typeof () changed
- From: Jan Nieuwenhuizen <janneke at gnu dot org>
- Date: Sat, 14 Aug 1999 21:08:53 +0200
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/