GCC 4.4.1 is refusing to find my injected-class-name within a ctor-initializer:
template
struct Base
{
Base(int x) {
Yeah, it is a bug.
I can reproduce it even more simply without the ctor-initialiser:
template <typename T>
struct Base
{
};
struct Derived : Base<int>
{
Base* ptr;
};
int main()
{
Derived d;
}
/**
* in GCC 4.4.1:
*
* error: ISO C++ forbids declaration of "Base" with no type
*/
And:
[C++11: 14.6.1/4]:
A lookup that finds an injected-class-name (10.2) can result in an ambiguity in certain cases (for example, if it is found in more than one base class). If all of the injected-class-names that are found refer to specializations of the same class template, and if the name is used as a template-name, the reference refers to the class template itself and not a specialization thereof, and is not ambiguous. [ Example:template <class T> struct Base { }; template <class T> struct Derived: Base<int>, Base<char> { typename Derived::Base b; // error: ambiguous typename Derived::Base<double> d; // OK };
—end example ]
Notice that the near-equivalent of my unambiguous usage is "OK". Alright, so Derived
is a class template here and not in my example, so it's not quite the same example. But I'm satisfied now that the entirety of 14.6.1 makes my code legal.
Turns out it had been raised as GCC bug 45515†, but since it had been fixed on head at the time there are very few details on it.
† Thanks BoBTFish!
Use : Base<int>(2) {}
(edit: sorry, I just took away the CRTP element as it's not needed to reproduce)