[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)
Dmitry Polukhin via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 11 08:20:47 PST 2024
================
@@ -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
More information about the cfe-commits
mailing list