Skip to content

Commit e232273

Browse files
authored
Merge pull request #82413 from swiftlang/egorzhdan/namespace-printer-null-crash
[cxx-interop] Fix printing of namespaces declared in bridging headers
2 parents c6d9b84 + cc9c51d commit e232273

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,10 @@ static void addNamespaceMembers(Decl *decl,
27402740
declOwner = declOwner->getTopLevelModule();
27412741
auto Redecls = llvm::SmallVector<clang::NamespaceDecl *, 2>(namespaceDecl->redecls());
27422742
std::stable_sort(Redecls.begin(), Redecls.end(), [&](clang::NamespaceDecl *LHS, clang::NamespaceDecl *RHS) {
2743+
// A namespace redeclaration will not have an owning Clang module if it is
2744+
// declared in a bridging header.
2745+
if (!LHS->getOwningModule() || !RHS->getOwningModule())
2746+
return (bool)LHS->getOwningModule() < (bool)RHS->getOwningModule();
27432747
return LHS->getOwningModule()->Name < RHS->getOwningModule()->Name;
27442748
});
27452749
for (auto redecl : Redecls) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace NS1 {
2+
namespace NS2 {
3+
4+
struct InBridgingHeader1 {};
5+
6+
} // namespace NS2
7+
} // namespace NS1
8+
9+
namespace NS1 {
10+
namespace NS2 {
11+
12+
struct InBridgingHeader2 {};
13+
14+
} // namespace NS2
15+
} // namespace NS1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-ide-test -print-header -header-to-print %S/Inputs/bridging-header.h -import-objc-header %S/Inputs/bridging-header.h -source-filename=%s -cxx-interoperability-mode=upcoming-swift | %FileCheck %s
2+
3+
// CHECK: struct InBridgingHeader1
4+
// CHECK: struct InBridgingHeader2

0 commit comments

Comments
 (0)