模板名称歧义:G++ vs clang++

发布于 2025-01-25 08:45:49 字数 1080 浏览 2 评论 0原文

前提:g ++和clang ++是已知有时不符合或不符合应用用于依赖名称的模板删除的规则

在这方面,以下代码 compiles 在g ++下,但不在clang ++下 clang ++:

template<class T1>
struct A {
    template <class T2>
    class Anested {
        public:
        typedef A<T2> Other;
    };
};

template <class T>
struct B {
    typedef B<T> Myself;
    typedef typename T::Anested<Myself>::Other Other; //clang++ requires "template" before "Anested" to compile
};

int main() {
    B<A<void>> b;
}

clang ++在这种情况下合规(不是吗?),但我想知道在这种语句中,“模板”关键字实际上是多余的。如果不是多余的,您能否举一些例子来证明扣除规则后面是G ++是有缺陷的吗?

Premise: g++ and clang++ are known to be sometime discordant or not compliant on applying the rules for template disambiguation for dependent names.

In this regard, the following code compiles under g++ but does not under clang++:

template<class T1>
struct A {
    template <class T2>
    class Anested {
        public:
        typedef A<T2> Other;
    };
};

template <class T>
struct B {
    typedef B<T> Myself;
    typedef typename T::Anested<Myself>::Other Other; //clang++ requires "template" before "Anested" to compile
};

int main() {
    B<A<void>> b;
}

clang++ is compliant in this case (isn't it?), but I am wondering whether the "template" keyword is actually redundant in this kind of statement. If it is not redundant, could you please make some examples to prove that the deduction rule followed by g++ is flawed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文