This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
static_cast problem
- To: gcc-bugs at sourceware dot cygnus dot com
- Subject: static_cast problem
- From: Ulrich Drepper <drepper at cygnus dot com>
- Date: 31 Dec 1999 20:51:21 -0800
- Reply-To: drepper at cygnus dot com (Ulrich Drepper)
I sumpled accross this problem in the current mainline gcc while
compiling Mozilla:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class foo
{
int a;
public:
operator const char *() { return (const char *) &a; }
foo(int b = 10) { a = b; }
};
int
main()
{
foo a;
#ifndef BUG
const char *t(a);
return (const char *) a == 0;
#else
return static_cast<const char *>(a) == 0;
#endif
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you compile it without BUG defined it works just fine. But with
BUG defined gcc complains
static_cast from `foo' to `const char'
(not a very informative message). Anyway, the C++ standard says that
the static_cast<T>(e) should succeed if a definition
T t(e)
is possible. But this is just what is done on the !BUG case.
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com `------------------------