[SemaCXX] Handle lack of TypeSourceInfo on special member functions in templated...
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 22 Jun 2021 22:14:26 +0000 (15:14 -0700)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Wed, 23 Jun 2021 00:26:05 +0000 (17:26 -0700)
commitc9aaf34b8db884faa3d3ced4d2fb88fd45697408
tree401dbfe5c9026754bea3fc300c699f6eca51349f
parent5c8659801a4976ef2b327f4071d98086efd42a36
[SemaCXX] Handle lack of TypeSourceInfo on special member functions in templated lambdas

During template instantiation involving templated lambdas, clang
could hit an assertion in `TemplateDeclInstantiator::SubstFunctionType`
since the functions are not associated with any `TypeSourceInfo`:

`assert(OldTInfo && "substituting function without type source info");`

This path is triggered when using templated lambdas like the one added as
a test to this patch. To fix this:

- Create `TypeSourceInfo`s for special members and make sure the template
instantiator can get through all patterns.
- Introduce a `SpecialMemberTypeInfoRebuilder` tree transform to rewrite
such member function arguments. Without this, we get errors like:

`error: only special member functions and comparison operators may be defaulted`

since `getDefaultedFunctionKind` can't properly recognize these functions
as special members as part of `SetDeclDefaulted`.

Fixes PR45828 and PR44848

Differential Revision: https://reviews.llvm.org/D88327
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp [new file with mode: 0644]