Is GCC 4.4.1 an error not accepting the name of the entered class in the ctor initializer?

GCC 4.4.1 refuses to find my injected class name inside ctor-initializer:

template <typename T> struct Base { Base(int x) {} }; struct Derived : Base<int> { Derived() : Base(2) {} }; int main() { Derived d; } 
 test2.cpp: In constructor "Derived::Derived()": test2.cpp:9: error: class "Derived" does not have any field named "Base" test2.cpp:9: error: no matching function for call to "Base<int>::Base()" test2.cpp:4: note: candidates are: Base<T>::Base(int) [with T = int] test2.cpp:3: note: Base<int>::Base(const Base<int>&) 

GCC 4.8 compiles it just fine .

I am sure that this should work, and I cannot find a standard wording that does not agree with me.

This is a GCC 4.4.1 bug, right?

(I looked at GCC Bugzilla, but nothing significant jumped at me.)

+7
c ++ gcc
source share
2 answers

Yes, this is a mistake.

I can play it even easier without 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]: search that finds a name with the introduced class (10.2) can lead to ambiguity in some cases (for example, if it is found in several base classes). If all the names of the entered classes that are found are related to specializations of the same class template, and if the name is used as the template name, the link refers to the class template itself, and not to its specialization, 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]

Note that almost the equivalent of my unambiguous use is OK. Ok, so Derived is a class template here, not in my example, so this is not exactly the same example. But now I am pleased that fully 14.6.1 makes my code legal.

Turns out he was raised as a GCC bug 45515 & dagger; but since she had her head fixed at a time when there were very few details on it.

& dagger; Thanks BoBTFish !

+4
source share

Use : Base<int>(2) {}

(editing: sorry, I just deleted the CRTP element as it is not needed for playback)

0
source share

All Articles