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

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 18:13:35 PST 2024


================
@@ -10057,15 +10057,18 @@ void ASTReader::finishPendingActions() {
       // For a function defined inline within a class template, force the
       // canonical definition to be the one inside the canonical definition of
       // the template. This ensures that we instantiate from a correct view
-      // of the template.
+      // of the template. This behaviour seems to be important only for inline
+      // friend functions. For normal member functions, it might results in
+      // selecting canonical decl from module A but body from module B.
       //
       // Sadly we can't do this more generally: we can't be sure that all
       // copies of an arbitrary class definition will have the same members
       // defined (eg, some member functions may not be instantiated, and some
       // special members may or may not have been implicitly defined).
-      if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
-        if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
-          continue;
+      if (FD->getFriendObjectKind())
----------------
ChuanqiXu9 wrote:

> I believe this is similar to what's happening when we import two C++20 modules and both have the same declaration in the GMF; but I'm on the contrary, not an expert in C++20 modules, so please correct me if I'm wrong

Correct relatively. But we forbid the checks for GMF (https://clang.llvm.org/docs/StandardCPlusPlusModules.html#object-definition-consistency) see reasons in the document.

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


More information about the cfe-commits mailing list