Addresses issue: https://bugs.llvm.org/show_bug.cgi?id=34728
Template type parameters can optionally have default values; at the first parameter declaration at which the default is declared, e.g. i in template <int i=0, class T>, this decl is treated as the "owner" of the default value, in this case 0.
However the serializer originally didn't record inherited-from-decl (owner) info at non-owners, only the default value in the owner's serialized bytes. So subsequent template declarations that should inherit this default value wouldn't, when used in a PCH or some serialized form.
For example, a precompiled header containing this:
template <int foo=1, class T> int func(T const&); template <int foo, class T> int func(T const&) { return foo; }
would not work in this source file, if used with PCH (but it would if it were included as an ordinary, non-pre-compiled header):
int main(int, char**) { return func(1.23); }
because of a spurious error about not being able to deduce foo, having lost the default value inheritance info during serialization:
candidate template ignored: couldn't infer template argument 'foo'
Tested with:
- New test cases added, now passing.
- Existing test cases look ok. (ninja check-clang)
The idea is to reconstruct the 'inherited default template argument' information when we read a template declaration and find it's a redeclaration of another one, rather than serializing it and deserializing it. (In particular, if an imported template redeclares a non-imported template or a template imported from an unrelated module, it won't know that the prior declaration had a default argument because it doesn't know what the prior declaration was.)
The problem with our implementation of that idea is these breaks: we're (incorrectly) assuming that a template parameter cannot have a default argument if there's a later template parameter that does not have one.
I removed the breaks in r338438, and it fixed your testcase (which I committed alongside that change). Can you check to see if that also fixes the original problem from which this was reduced? Thanks!