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]

dynamic_cast<T>(v) fails for T qualified from global namespace


The short program at end here produces error messages under both 2.95.3 and
3.x at
http://www.codesourcery.com/gcc-compile.shtml
I don't see anything in the c++ spec that disallows globally qualified
class names for T in dynamic_cast<T>(v); . 

Sorry if this is a duplicate report -- haven't been able to
browse the web archive of the bug reports (specifically, gnats
wants a username and password at
http://gcc.gnu.org/cgi-bin/gnatsweb.pl
just to browse priors, which is itself a bug, imo.)
compiler output:
/usr/tmp/@19711.7.cc: In function `int main()':
      /usr/tmp/@19711.7.cc:37: parse error before `[' token
      /usr/tmp/@19711.7.cc:42: parse error before `[' token

Ben Allan

namespace n1 {
  class foo {
  public:
    virtual ~foo() {}
    virtual void doIt()  =0;
  };

  class bar : public virtual foo {
  public:
    bar() {}
    virtual ~bar() {}
    void doIt()  { i=2;}
  private:
    int i;
  };

} ;
extern void exit(int c);
int main() {

  ::n1::foo *gfp = 0;
  ::n1::foo *gfp2 = 0;
  ::n1::bar gb;
  ::n1::bar *gbp;

  n1::foo *fp = 0;
  n1::foo *fp2 = 0;
  n1::bar b;
  n1::bar *bp;

  bp = &b;
  gbp = &gb;

  fp = dynamic_cast<n1::foo *>(bp);
  if (fp == 0) { exit(1); }
  fp2 = dynamic_cast<::n1::foo *>(bp); // ! err
  if (fp2 == 0) { exit(2); }

  gfp = dynamic_cast<n1::foo *>(gbp);
  if (gfp == 0) { exit(3); }
  gfp2 = dynamic_cast<::n1::foo *>(gbp); // ! err
  if (gfp2 == 0) { exit(4); }
  return 0;
}


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