This code used to compile in Clang 3.8, and still compiles in VS 2017, but started emitting an error in Clang 3.9.
template <typename D, typename ... I>
struct impl : I ...
{};
template <typename D, typename ... I>
void f(impl<D, I...> const&)
{}
struct A : impl<A> {};
struct B : impl<B, A> {};
int main()
{
f(A());
f(B()); // Error
}
Clang 3.9 says
<source>:15:5: error: no matching function for call to 'f'
f(B());
^
<source>:6:6: note: candidate template ignored: failed template argument deduction
void f(impl<D, I...> const&)
^
All three compilers in action: https://godbolt.org/g/OKFpPl
I want f(A())
to deduce D = A, I... = <>
and f(B())
to deduce D = B, I... = A
, which is then deducible as an instance of impl
. My end goal is to detect type in impl
's parameter pack that are themselves instances of impl
. Am I going about this the wrong way?
Not sure but...
Your B
class inherit from impl<B, A>
that inherit from impl<A>
.
So B
inherit from a couples of different impl<D, I...>
base classes, so the type deduction is ambigous (D == B
and I... == <A>
or D == A
and I... == <>
).
So I think that clang 3.8 is wrong and that 3.9 is right.
My end goal is to detect type in impl's parameter pack that are themselves instances of impl. Am I going about this the wrong way?
Yes, you're doing it in the wrong way (I think).