From cba31ae148f3166b06e5862ed6b6bcf4a3131c0e Mon Sep 17 00:00:00 2001 From: jase231 Date: Wed, 5 Aug 2026 12:17:48 +0200 Subject: [PATCH] [cling] Always add primary NamespaceDecl to fNSSet When a namespace is multiply-defined, clang designates one as the primary. When it queries ROOT for external decls, it always passes the primary context, so fNSFromRootmaps is queried with the primary. This change adds the primary into the set alongside any potential non-primary redeclared context, so ROOT correctly reports that namespace as an autoload candidate. --- core/metacling/src/TCling.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 998e29cec2d64..91677fc0fa39f 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -5872,6 +5872,16 @@ namespace { nsDecl->setHasExternalVisibleStorage(); fNSSet.insert(nsDecl); + + // When cling eventually queries fNSSet/fNSFromRootmaps, it always does so + // using the primary DeclContext. Therefore we need to store + // the namespace's primary, not just nsDecl which might just + // be a non-primary declaration context for the namespace. + auto *primaryNsDecl = dyn_cast_or_null(nsDecl->getPrimaryContext()); + if (primaryNsDecl && primaryNsDecl != nsDecl) { + primaryNsDecl->setHasExternalVisibleStorage(); + fNSSet.insert(primaryNsDecl); + } return true; } bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl* specDecl) {