[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 09:27:01 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();
----------------
ilya-biryukov wrote:

There's a use of `D->getTemplatedDecl()` below, on line 2006 in `D->getTemplatedDecl()->isThisDeclarationADefinition->isThisDeclarationADefinition()`.

I am wondering if we should update the use there too?
I suspect that even if it doesn't matter, we're better off using `TemplatedDecl` there too (it's more "obviously" correct)

https://github.com/llvm/llvm-project/pull/111992


More information about the cfe-commits mailing list