成员模板专业化不使用 clang 编译

Member template specialization does not compile with clang

考虑以下程序:

struct S {
    enum E {
        e
    };
    template<E> void f() = delete;
};

template<> void S::f<S::E::e>() {}

int main() {
    S s;
    s.f<S::E::e>();
}

GCC 5.4.0 编译代码,而 clang 3.8.0 失败:

$ clang++ -std=c++14 main.cpp 
main.cpp:10:20: error: redefinition of 'f'
template<> void S::f<S::E::e>() {
                   ^
main.cpp:8:20: note: previous definition is here
template<> void S::f<S::E::e>();
                   ^
main.cpp:14:11: error: no matching member function for call to 'f'
        s.f<S::E::e>();
        ~~^~~~~~~~~~
main.cpp:5:22: note: candidate template ignored: substitution failure [with [=11=] = S::E::e]
    template<E> void f() = delete;
                     ^
2 errors generated.

clang是正确的而GCC是错误的还是相反?请注意,如果删除了 delete 说明符,则 clang 会编译代码。

这似乎是缺陷报告Explicit specialization of deleted function template , as you can see from here自 3.9.0 以来,该问题似乎已在 clang 中修复。