zyn0217 wrote:

Just get back to this again. So, I have explored the other case and found it 
particular to explicit template arguments. In fact, we could slightly revise 
the motivating case to

```cpp
template <class T>
concept C = false;

template <typename U, template <C> typename T>
int wow(T<U> ts);

template <typename T> struct S {};

int main() { return wow<int>(S<int>{}); }
```

with an *explicit* template argument `int`. This takes us to such the branch in 
`DeduceTemplateArguments`,

https://github.com/llvm/llvm-project/blob/e0c554ad87d18dcbfcb9b6485d0da800ae1338d1/clang/lib/Sema/SemaTemplateDeduction.cpp#L4222-L4232

which would deduce the remaining template arguments from the given 
`FunctionTemplate` and fall into our `getTemplateInstantiationArgs` at the end 
of the day. It is also interesting to notice that the given 
`TemplateTemplateParmDecl` originates from this `FunctionTemplate`, and the 
surrounding `DeclContext`s for these `Decl`s has already been *redirected* to 
its associated `FunctionDecl` at `AdoptTemplateParameterList`.

https://github.com/llvm/llvm-project/blob/59af659ee3c790d06cb5e2bf580e042547c24323/clang/lib/AST/DeclTemplate.cpp#L202-L206


Therefore, I think our assumption that the `TemplateTemplateParmDecl` always 
resides in the `TranslationUnitDecl` is probably wrong. And, it is indeed murky 
that the `DeclContext`s where these `Decl`s live depend on the callers to this 
function...

Removing these checks works for the code above and, fortunately, doesn't fail 
any tests.

@erichkeane WDYT?

https://github.com/llvm/llvm-project/pull/76811
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to