Clang and GCC disagree in auto specifier for non-type template parameter in a casting C++17

六月ゝ 毕业季﹏ 提交于 2019-12-03 11:00:45

This is a clang bug. Here's a short reproduction:

template <int A>
struct X {
    template <auto B>
    X<B> foo();
};

template <int A>
template <auto B>
X<B> X<A>::foo() {
    return {};
}

If auto B is replaced by int B, clang accepts it. gcc accepts it as-is. For clang, this is only a problem with the nested template declarations. There's nothing about auto as a placeholder template non-type parameter that would prevent it from being used to define something out-of-line.

While filing a new clang bug, I found 35655, with an even shorter reproduction:

template<typename>
struct S {
    template<auto n>
    static void f() {
        +n;
    }
};

which fails with:

source.cpp:5:3: error: invalid argument type 'auto' to unary expression
                +n;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!