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

static_cast problem


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   `------------------------


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