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

后端 未结 1 707
小鲜肉
小鲜肉 2021-02-12 18:12

I basically have a class that depends on a non-type template parameter. I defined a casting so an object of non-type template parameter N can convert to another of

相关标签:
1条回答
  • 2021-02-12 18:55

    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;
    
    0 讨论(0)
提交回复
热议问题