aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ASTImporter.cpp
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2025-05-06 10:17:26 +0200
committerGitHub <noreply@github.com>2025-05-06 10:17:26 +0200
commit4b30b3f901b00da1bd1f70e9ca9086e349c7cca0 (patch)
tree1cb7d56f4330d32df1a92940ad2e64d090d2b9ab /clang/lib/AST/ASTImporter.cpp
parent6d85de88c426a40b8e5d3cfcb0ed6564c7df12be (diff)
downloadllvm-4b30b3f901b00da1bd1f70e9ca9086e349c7cca0.zip
llvm-4b30b3f901b00da1bd1f70e9ca9086e349c7cca0.tar.gz
llvm-4b30b3f901b00da1bd1f70e9ca9086e349c7cca0.tar.bz2
[clang][ASTImporter] Fix AST import if anonymous namespaces are merged (#128735)
Fix of a faulty case that is shown in the second of the added tests (an anonymous namespace is imported that resides in a `extern "C"` block).
Diffstat (limited to 'clang/lib/AST/ASTImporter.cpp')
-rw-r--r--clang/lib/AST/ASTImporter.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index eb0e686..b481ad5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2628,11 +2628,12 @@ ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) {
if (!Name) {
// This is an anonymous namespace. Adopt an existing anonymous
// namespace if we can.
- // FIXME: Not testable.
- if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
+ DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
+ if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
MergeWithNamespace = TU->getAnonymousNamespace();
else
- MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
+ MergeWithNamespace =
+ cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
} else {
SmallVector<NamedDecl *, 4> ConflictingDecls;
auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);