[Clang] 20.1.0 fails to compile variadic partial template specialization
The following minimum repro used to compile successfully and work correctly with Clang 19.1.4, but fails to compile with Clang 20.1.0:
#include <iostream>
#include <utility>
template <typename> struct s;
template <typename T> constexpr std::size_t size = s<T>::value;
// list
template <template <typename...> typename L, typename... U>
struct s<L<U...>> { static constexpr std::size_t value = sizeof...(U); };
// sequence
template <typename T, template <typename, T...> typename L, T... U>
struct s<L<T, U...>> { static constexpr std::size_t value = sizeof...(U); };
#define TEST(N) \
std::cout << "[" #N "]: " << size<std::make_index_sequence<N>> << std::endl;
int main() {
TEST(0); TEST(1); TEST(2);
TEST(3); TEST(4); TEST(5);
}
Compiler output in Clang 20.1.0:
$ clang++ -Wall -std=c++23 sz.cpp -o sz
../sz.cpp:5:52: error: implicit instantiation of undefined template 's<std::integer_sequence<unsigned long>>'
5 | template <typename T> constexpr std::size_t size = s<T>::value;
| ^
../sz.cpp:17:3: note: in instantiation of variable template specialization 'size<std::integer_sequence<unsigned long>>' requested here
17 | TEST(0);
| ^
../sz.cpp:14:32: note: expanded from macro 'TEST'
14 | std::cout << "[" #N "]: " << size<std::make_index_sequence<N>> << std::endl;
| ^
../sz.cpp:4:28: note: template is declared here
4 | template <typename> struct s;
| ^
@llvm/issue-subscribers-clang-frontend
Author: Marcelo Juchem (juchem)
template <typename> struct s; template <typename T> constexpr std::size_t size = s<T>::value; // list template <template <typename...> typename L, typename... U> struct s<L<U...>> { static constexpr std::size_t value = sizeof...(U); }; // sequence template <typename T, template <typename, T...> typename L, T... U> struct s<L<T, U...>> { static constexpr std::size_t value = sizeof...(U); };
#define TEST(N)
std::cout << "[" #N "]: " << size<std::make_index_sequence<N>> << std::endl;
int main() { TEST(0); TEST(1); TEST(2); TEST(3); TEST(4); TEST(5); }
Compiler output in Clang 20.1.0:
$ clang++ -Wall -std=c++23 sz.cpp -o sz ../sz.cpp:5:52: error: implicit instantiation of undefined template 's<std::integer_sequence<unsigned long>>' 5 | template <typename T> constexpr std::size_t size = s<T>::value; | ^ ../sz.cpp:17:3: note: in instantiation of variable template specialization 'size<std::integer_sequence<unsigned long>>' requested here 17 | TEST(0); | ^ ../sz.cpp:14:32: note: expanded from macro 'TEST' 14 | std::cout << "[" #N "]: " << size<std::make_index_sequence<N>> << std::endl; | ^ ../sz.cpp:4:28: note: template is declared here 4 | template <typename> struct s; | ^
</details>
CC @erichkeane @cor3ntin
Looks like #130778
CC @mizvekov @AaronBallman
Yeah, this is a duplicate of #130778.
Fixing the user code in this case is very simple, just change:
// sequence
template <typename T, template <typename, T...> typename L, T... U>
// sequence
template <template <typename V, V...> typename L, typename T, T... U>
Ie do with T the same thing you had to do with U anyway.
https://compiler-explorer.com/z/5f6YzqKTh