[clang] [Clang][Sema] Expose static inline functions from GMF (PR #104701)

Jan Kokemüller via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 29 01:16:10 PST 2024


================
@@ -6926,11 +6926,26 @@ void Sema::AddOverloadCandidate(
     /// have linkage. So that all entities of the same should share one
     /// linkage. But in clang, different entities of the same could have
     /// different linkage.
-    NamedDecl *ND = Function;
-    if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
+    const NamedDecl *ND = Function;
+    bool IsImplicitlyInstantiated = false;
+    if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
       ND = SpecInfo->getTemplate();
-
-    if (ND->getFormalLinkage() == Linkage::Internal) {
+      IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
+                                 TSK_ImplicitInstantiation;
+    }
+
+    /// Don't remove inline functions with internal linkage from the overload
+    /// set if they are declared in a GMF.
+    /// The global module is meant to be a transition mechanism for C and C++
+    /// headers.
+    /// Inline functions with internal linkage are a common pattern in headers
+    /// to avoid ODR issues.
----------------
jiixyj wrote:

Sorry for the delay! I have now updated the comment to include the fact that this fix/workaround violates [basic.link]p17, strictly speaking. I've also merged the main branch. On my machine, the (new) tests in `./tools/clang/test/Modules` still pass. Does this work for you? Thanks again for the review!

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


More information about the cfe-commits mailing list