I think I hit a template type deduction bug in all the compilers, but before reporting it I want to be sure I did not miss something.
Consider an example:
#include <utility>
template <std::size_t... I, typename... T>
void foo(std::index_sequence<I...>, decltype(I)..., T...) {}
int main()
{
foo(std::make_index_sequence<3>{}, 1, 2, 3, 4, 5);
}
decltype(I)
is used here to make MWE shorter.
- GCC:
error: too few arguments to function
- Clang crashes with
error: no matching function for call to 'foo'
- MSVC crashes with
error C3543: 'unknown-type': does not contain a parameter pack
I don't understand why it fails to deduct T
, especially because it works if I replace parameter pack with varargs (except MSVC, it has ICE again).
template <std::size_t... I>
void foo(std::index_sequence<I...>, decltype(I)..., ...) {}
There are many other ways to make what I want, but this is the shortest way and I do not see any reasons it should fail.
Update: The know valid example with substitution on deducible is:
template <typename T>
struct type_identity
{ using type = T; };
template <typename T, typename... U>
void foo(T, typename type_identity<T>::type, U...) {}
int main()
{
foo(1, 2, 3, 4, 5);
}
Update #2 The modified version of the original example does not crash Clang, but a note on the error is strange note: candidate template ignored: deduced conflicting types for parameter 'T' (<int, int, int> vs. <>)
#include <utility>
template <typename T>
struct type_identity
{ using type = T; };
template <typename...>
struct type_pack {};
template <typename... T, typename... U>
void foo(type_pack<T...>, typename type_identity<T>::type..., U...) {}
int main()
{
foo(type_pack<int, int, int>{}, 1, 2, 3, 4, 5);
}