c – GCC 4.4.1错误是因为不接受ctor-initializer中的注入类名?

前端之家收集整理的这篇文章主要介绍了c – GCC 4.4.1错误是因为不接受ctor-initializer中的注入类名?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
GCC 4.4.1拒绝在ctor-initializer中找到我的注入类名:
template <typename T>
struct Base
{
    Base(int x) {}
};

struct Derived : Base<int>
{
    Derived() : Base(2) {}
};

int main()
{
    Derived d;
}

06001

但GCC 4.8 compiles it just fine.

我确信这应该有用,我找不到任何不同意我的标准措辞.

这是一个GCC 4.4.1错误,对吗?

(我确实在搜索GCC Bugzilla,但没有任何相关内容突然出现在我身上.)

解决方法

是的,这是一个错误.

如果没有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
 */

和:

[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:

06001

—end example ]

请注意,我的明确用法几乎等同于“OK”.好吧,所以Derived是一个类模板,而不是我的例子,所以它不是完全相同的例子.但我现在感到满意的是,整个14.6.1使我的代码合法化.

事实证明它已被提升为GCC bug 45515†,但由于它当时已被固定在头上,因此它的细节很少.

†感谢BoBTFish

猜你在找的C&C++相关文章