The problem was with constructors that have parameters that refer to previous ones, such as D below:
template <size_t> struct A {}; template <class T> struct D { D(T t, A<sizeof(t)>); }; int main() { D d(0, A<4>()); }
We were canonicalizing the type of A<sizeof(t)> to refer to the t in the constructor as opposed to the new one in the deduction guide. This is because ParmVarDecls are profiled based on their type and offset, so the two ParmVarDecls profiled to the same ID, despite them belonging to distinct functions. The fix for this here is to add a bit to ParmVarDecl, IsParamOfDeductionGuide, that tracks if this ParmVarDecl is "spliced" from another function. This makes references to the new ParmVarDecl not canonicalize to the previous ParmVarDecl.
This patch also fixes a closely related bug where newly created ParmVarDecls were not being added to the CurrentInstantiationScope, leading to an assert when we try to find it later.
rdar://41330135
Thanks for taking a look!
Erik
This is really the problem: we shouldn't be doing a full canonicalization step here. I expect that even with your patch applied we'll still see problems for cases like:
... because we'll canonicalize the second parameter of B's deduction guide to have type X<sizeof(t)> (where that's the t from A's deduction guide).
So I think we should look at fixing the FIXME here properly. There seem to be at least two viable options:
Both of these seem pretty tricky to get right, though, which is why we currently use the canonicalization hack :(