[clang] [clang] Fix incorrect 'namespace' in diagnostic for out-of-line declarations (PR #230630)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 19:17:04 PDT 2026


================
@@ -6469,9 +6469,22 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
         // The cases that DC is not NamespaceDecl should be handled in
         // CheckRedeclarationExported.
         return false;
-    } else
+    } else {
+      unsigned DCKind = diag::EnclosingDeclKind::Namespace;
+      if (auto *TD = dyn_cast<TagDecl>(DC)) {
+        if (TD->isStruct())
+          DCKind = diag::EnclosingDeclKind::Struct;
+        else if (TD->isClass())
+          DCKind = diag::EnclosingDeclKind::Class;
+        else if (TD->isUnion())
+          DCKind = diag::EnclosingDeclKind::Union;
+        else if (TD->isEnum())
+          DCKind = diag::EnclosingDeclKind::Enum;
----------------
zwuis wrote:

I'd like to see tests for these branches.

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


More information about the cfe-commits mailing list