Skip to content

Commit f774052

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 1549291 commit f774052

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

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

0 commit comments

Comments
 (0)