g++ bug?

Thomas, Steve steve.thomas@mbda.co.uk
Mon Oct 4 12:21:00 GMT 2004


Hi,

I think I have found a bug in g++, to do with scoping rules, but I'm not
sufficiently expert on the language to be sure. Here is a simple test case:

#include <stdio.h>

class ZZZ {
public:
  ZZZ ()
  {
    printf ("ZZZ constructor\n");
  }
  int aaa;
};

template<typename T>
class BBB {
public:
  void ZZZ (void)
  {
    printf ("BBB.ZZZ\n");
  }
};

template<typename T>
class AAA : public BBB<T> {
public:

  void YYY (void)
  {
    ZZZ();
  }
};

int main (void)
{
  AAA<int> a;
  a.YYY();
  return 0;
}

When built & run with g++ V3.3.1, it generates the output "ZZZ constructor".
In other words, the call to ZZZ() in AAA.YYY() has called the constructor of
class ZZZ in preference to function ZZZ in the base class. This doesn't seem
right to me. This behaviour only seems to occur if classes AAA & BBB are
templates, but I haven't experimented too widely to be sure of this.

Any comments anyone?

Thanks,

Steve Thomas
MBDA (UK)




********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************



More information about the Gcc mailing list