次のコードを検討してください。
template <typename T> using VoidT = void;
class A {
public:
using TEST = int;
};
class C {
public:
using DIFFERENT = int;
};
template <typename T, typename Enable = void>
class B {
public:
B() = delete;
};
template <typename T>
class B<T, VoidT<typename T::TEST>> {
public:
B() = default;
};
template <typename T>
class B<T, VoidT<typename T::DIFFERENT>> {
public:
B() = default;
};
int main() {
B<A> a;
B<C> b;
return 0;
}
g ++-4.8.5を使用してこのコードをコンパイルすると、次のエラーメッセージが表示されます。
~/test/compile_test> g++ -std=c++11 test.cpp
test.cpp:31:7: error: redefinition of ‘class B<T, void>’
test.cpp:24:7: error: previous definition of ‘class B<T, void>’
ただし、g ++-8.3(ideoneなど)を使用してコンパイルすると、コードがコンパイルされ、さまざまな特殊化が正しく処理されます。これは修正されたGCCのバグですか、それとも何らかの理由で未定義の動作を呼び出していますか(したがって、コンパイラの動作の違いは問題点です-未定義です)?