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) {