Skip to content

Commit d71fb50

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 6414d61 commit d71fb50

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
@@ -10281,15 +10281,18 @@ void ASTReader::finishPendingActions() {
1028110281
// For a function defined inline within a class template, force the
1028210282
// canonical definition to be the one inside the canonical definition of
1028310283
// the template. This ensures that we instantiate from a correct view
10284-
// of the template.
10284+
// of the template. This behaviour seems to be important only for inline
10285+
// friend functions. For normal member functions, it might results in
10286+
// selecting canonical decl from module A but body from module B.
1028510287
//
1028610288
// Sadly we can't do this more generally: we can't be sure that all
1028710289
// copies of an arbitrary class definition will have the same members
1028810290
// defined (eg, some member functions may not be instantiated, and some
1028910291
// special members may or may not have been implicitly defined).
10290-
if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
10291-
if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
10292-
continue;
10292+
if (FD->getFriendObjectKind())
10293+
if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent()))
10294+
if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
10295+
continue;
1029310296

1029410297
// FIXME: Check for =delete/=default?
1029510298
const FunctionDecl *Defn = nullptr;

0 commit comments

Comments
 (0)