================
@@ -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();
----------------
dmpolukhin wrote:

`FunctionDecl::hasBody` is doing what you described for `getRedeclWithDef`, see 
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/Decl.cpp#L3163 and 
if I used it here or implement similar code here, it fails several clang tests. 
It is very unfortunate that `Redeclarable` is used for two things: real 
redeclaration and AST merges. Moreover it look like there is no way to 
distinguish these two cases. I need to use different decl only if the decl was 
`doesThisDeclarationHaveABody() == true` but it is no longer the case due to 
AST merge.

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

Reply via email to