dynamic cast of qualified member name

Nathan Sidwell nathan@acm.org
Fri Jan 8 07:09:00 GMT 1999

egcs++ doesn't permit a dynamic cast of the form
dynamic_cast<T *>(A::m), even though dynamic_cast<T *>(m) is
legal (A::m and m being the same type).

Here is a test case,
struct M
  virtual ~M();

struct A
  M *m;
  void fn();

void A::fn()
  M *m = A::m;
  M *n;
  n = dynamic_cast<M *>(m);
  n = (M*)A::m;
  n = static_cast<M *>(A::m); 
  n = static_cast<M *>(&A::m);
  n = dynamic_cast<M *>(A::m); 
  n = dynamic_cast<M *>(&A::m);
  n = dynamic_cast<M *>(((A *)this)->m);
 and here is the compiler output
nathan@manao:85>uname -a       
SunOS manao 5.6 Generic_105181-03 sun4u sparc SUNW,Ultra-5_10
nathan@manao:86>ss-g++ -v -c dyncast.ii         
Reading specs from /home/staff/nathan/solaris/local/sparc-SunOS_5/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.92.34/specs
gcc version egcs-2.92.34 19990103 (gcc2 ss-980609 experimental)
 /home/staff/nathan/solaris/local/sparc-SunOS_5/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.92.34/cc1plus dyncast.ii -quiet -version -o /var/tmp/cc59in0c.s
GNU C++ version egcs-2.92.34 19990103 (gcc2 ss-980609 experimental) (sparc-sun-solaris2.6) compiled by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release).
dyncast.ii: In method `void A::fn()':
dyncast.ii:19: static_cast from `M * A::*' to `M *'
dyncast.ii:20: cannot dynamic_cast `this ->* A::m' (of type `struct M * A::*') to type `struct M *'
dyncast.ii:21: cannot dynamic_cast `&A::m' (of type `struct M * A::*') to type `struct M *'

I expected the diagnostics for lines 19 and 21, although that for
19 is rather abrupt -- something like 'cannot static_cast from ...'
might be better.

It is line 20's diagnostic which I think is wrong. It appears to be
implicitly converting A::m to a ptr to member, and hence getting a
similar problem as line 21 (although with a slightly different

I believe this to be a bug.

Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk

More information about the Gcc-bugs mailing list