@@ -6926,11 +6926,26 @@ void Sema::AddOverloadCandidate(
69266926 /// have linkage. So that all entities of the same should share one
69276927 /// linkage. But in clang, different entities of the same could have
69286928 /// different linkage.
6929- NamedDecl *ND = Function;
6930- if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
6929+ const NamedDecl *ND = Function;
6930+ bool IsImplicitlyInstantiated = false;
6931+ if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
69316932 ND = SpecInfo->getTemplate();
6932-
6933- if (ND->getFormalLinkage() == Linkage::Internal) {
6933+ IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
6934+ TSK_ImplicitInstantiation;
6935+ }
6936+
6937+ /// Don't remove inline functions with internal linkage from the overload
6938+ /// set if they are declared in a GMF.
6939+ /// The global module is meant to be a transition mechanism for C and C++
6940+ /// headers.
6941+ /// Inline functions with internal linkage are a common pattern in headers
6942+ /// to avoid ODR issues.
6943+ const bool IsInlineFunctionInGMF =
6944+ Function->getOwningModule() &&
6945+ Function->getOwningModule()->isGlobalModule() &&
6946+ (IsImplicitlyInstantiated || Function->isInlined());
6947+
6948+ if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) {
69346949 Candidate.Viable = false;
69356950 Candidate.FailureKind = ovl_fail_module_mismatched;
69366951 return;
0 commit comments