[Clang] Suboptimal diagnostics on missing template arguments in the type of explicit instantiation of variable template
The following C++17 code is accepted by GCC and MSVC, but rejected by Clang.
template <class T>
struct A { A(T) {} };
template <class>
A a{0};
template A a<int>;
Output:
<source>:7:10: error: 'auto' variable template instantiation is not allowed
7 | template A a<int>;
| ^
See https://compiler-explorer.com/z/PerPhffKG.
@llvm/issue-subscribers-clang-frontend
Author: None (MagentaTreehouse)
template <class T>
struct A { A(T) {} };
template <class>
A a{0};
template A a<int>;
Output:
<source>:7:10: error: 'auto' variable template instantiation is not allowed
7 | template A a<int>;
| ^
See https://compiler-explorer.com/z/PerPhffKG.
It looks like the code is invalid per [dcl.type.class.deduct]:
If a placeholder for a deduced class type appears as a decl-specifier in the decl-specifier-seq of an initializing declaration ([dcl.init]) of a variable, the declared type of the variable shall be cv T, where T is the placeholder. [...]
A placeholder for a deduced class type can also be used in the type-specifier-seq in the new-type-id or type-id of a new-expression ([expr.new]), as the simple-type-specifier in an explicit type conversion (functional notation), or as the type-specifier in the parameter-declaration of a template-parameter ([temp.param]). A placeholder for a deduced class type shall not appear in any other context.
But Clang's diagnostics can be improved, because the code doesn't say auto anywhere.