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