g++ bug?

Nathan Sidwell nathan@codesourcery.com
Mon Oct 4 13:00:00 GMT 2004


Thomas, Steve wrote:
> 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:

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

Not a bug. BBB<T> is a dependent base, and therefore not searched until
instantiation time.  The ZZZ() lookup is bound at definition time, and as
it is a non-dependent expression the global ::ZZZ type is found.

If you want BBB<T>::ZZZ you must make the expression dependent like so,
	this->ZZZ ();

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk




More information about the Gcc mailing list