I was writing an out-of-class destructor definition for a class template when I noticed that the program compiles with clang with c++17 and c++20 and also with gcc with c++17 but rejected with gcc c++20. Demo.
template<typename T>
struct C
{
~C();
};
template<typename T>
C<T>::~C<T>() //accepted by compilers
{
}
int main()
{
C<int> c;;
}
The result of the above program is summarized in the below table:
Compiler | C++ Version | Accepts-Code |
---|---|---|
GCC | C++17 | Yes |
GCC | C++20 | No |
GCC | C++2b | No |
Clang | C++17 | Yes |
Clang | C++20 | Yes |
Clang | C++2b | Yes |
MSVC | C++17 | Yes |
MSVC | C++20 | Yes |
As we can see in the above both of the compilers accept the code except that gcc with c++20 and onwards reject it with the error error: template-id not allowed for destructor
.
So, my question is which compiler is right here(if any).