================
@@ -1976,14 +1976,16 @@
TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
if (!InstParams)
return nullptr;
+ // Use canonical templated decl because only canonical decl has body
+ // if declarations were merged during loading from modules.
+ FunctionDecl *TemplatedDecl = D->getTemplatedDecl()->getCanonicalDecl();
----------------
ChuanqiXu9 wrote:
Such problems are pretty common and I thought if we can make it generally. And
also I am wondering the definition for canonical decl. But this is not the
problem of this patch. This won't make a blocker issue.
I roughly remember that the definition of `CanonicalDecl` are the first
declaration not the declaration has the definition. So may be it is better to
write this as:
```
FunctionDecl *TemplatedDecl = D->getTemplatedDecl();
if (TemplatedDecl doesn't have a body)
iterate redecls of TemplatedDecl and assign the decl that has a body to
`TemplatedDecl`.
```
(maybe we should have an interface like something like `getRedeclWithDef()` if
we don't have one)
And also I admit there some existing codes use `getCanonicalDecl` to try to do
the similar things, but they are their problems.
https://github.com/llvm/llvm-project/pull/111992
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits