[all-commits] [llvm/llvm-project] af10d6: [clang] don't instantiate templates with injected ...
Matheus Izvekov via All-commits
all-commits at lists.llvm.org
Wed Sep 29 14:19:27 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: af10d6f350ff3e92c6ffae66cc9dac36884cdd55
https://github.com/llvm/llvm-project/commit/af10d6f350ff3e92c6ffae66cc9dac36884cdd55
Author: Matheus Izvekov <mizvekov at gmail.com>
Date: 2021-09-29 (Wed, 29 Sep 2021)
Changed paths:
M clang/lib/Sema/SemaTemplateInstantiate.cpp
A clang/test/SemaTemplate/generic-lambda.cpp
Log Message:
-----------
[clang] don't instantiate templates with injected arguments
There is a special situation with templates in local classes,
as can be seen in this example with generic lambdas in function scope:
```
template<class T1> void foo() {
(void)[]<class T2>() {
struct S {
void bar() { (void)[]<class T3>(T2) {}; }
};
};
};
template void foo<int>();
```
As a consequence of the resolution of DR1484, bar is instantiated during the
substitution of foo, and in this context we would substitute the lambda within
it with it's own parameters "injected" (turned into arguments).
This can't be properly dealt with for at least a couple of reasons:
* The 'TemplateTypeParm' type itself can only deal with canonical replacement
types, which the injected arguments are not.
* If T3 were constrained in the example above, our (non-conforming) eager
substitution of type constraints would just leave that parameter dangling.
Instead of substituting with injected parameters, this patch just leaves those
inner levels unreplaced.
Since injected arguments appear to be unused within the users of
`getTemplateInstantiationArgs`, this patch just removes that support there and
leaves a couple of asserts in place.
Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>
Reviewed By: rsmith
Differential Revision: https://reviews.llvm.org/D110727
More information about the All-commits
mailing list