Skip to content

Commit 0d02e79

Browse files
committed
[C++20][Modules] Load function body from the module that gives cannonical decl
Summary: Fix crash from reproducer provided in llvm#109167 (comment) Test Plan: TBD
1 parent ff04bb8 commit 0d02e79

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10057,15 +10057,18 @@ void ASTReader::finishPendingActions() {
1005710057
// For a function defined inline within a class template, force the
1005810058
// canonical definition to be the one inside the canonical definition of
1005910059
// the template. This ensures that we instantiate from a correct view
10060-
// of the template.
10060+
// of the template. This behaviour seems to be important only for inline
10061+
// friend functions. For normal member functions, it might results in
10062+
// selecting canonical decl from module A but body from module B.
1006110063
//
1006210064
// Sadly we can't do this more generally: we can't be sure that all
1006310065
// copies of an arbitrary class definition will have the same members
1006410066
// defined (eg, some member functions may not be instantiated, and some
1006510067
// special members may or may not have been implicitly defined).
10066-
if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
10067-
if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
10068-
continue;
10068+
if (FD->getFriendObjectKind())
10069+
if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
10070+
if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
10071+
continue;
1006910072

1007010073
// FIXME: Check for =delete/=default?
1007110074
const FunctionDecl *Defn = nullptr;

0 commit comments

Comments
 (0)