[clang] [clang][Modules] Keep current-TU global-module-fragment internal-linkage functions viable in overload resolution (PR #210825)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 20 18:46:57 PDT 2026


================
@@ -7388,7 +7388,21 @@ void Sema::AddOverloadCandidate(
         Function->isFromGlobalModule() &&
         (IsImplicitlyInstantiated || Function->isInlined());
 
-    if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) {
+    /// An internal-linkage function declared in the global module fragment of
+    /// the *current* translation unit (as opposed to one imported from another
+    /// module's BMI) is usable within this module unit ([module.global.frag]
+    /// p1), even a plain 'static' (non-inline) helper. Such a helper is dropped
+    /// here only because Function->isInAnotherModuleUnit() misclassifies it
+    /// when the enclosing template is instantiated after the GMF is closed
+    /// (the current named module is not yet in scope), which produced a bogus
+    /// "no matching function" error with no candidate notes. Only genuinely
+    /// cross-unit uses (Function came from an imported BMI) stay subject to the
+    /// internal-linkage rule.
+    const bool IsCurrentUnitGMFDecl =
+        Function->isFromGlobalModule() && !Function->isFromASTFile();
----------------
ChuanqiXu9 wrote:

I prefer to use Sema::getCurrentModule and compare the result than `isFromASTFile`

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


More information about the cfe-commits mailing list