diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 371aea8088a0..cdd8487c555e 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1016,10 +1016,12 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { StoredDeclsMap *Map = NS->buildLookup(); SmallVector, 16> LookupResults; - LookupResults.reserve(Map->size()); - for (auto &Entry : *Map) - LookupResults.push_back( - std::make_pair(Entry.first, Entry.second.getLookupResult())); + if (Map) { + LookupResults.reserve(Map->size()); + for (auto &Entry : *Map) + LookupResults.push_back( + std::make_pair(Entry.first, Entry.second.getLookupResult())); + } std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); for (auto &NameAndResult : LookupResults) { diff --git a/clang/test/Modules/Inputs/namespaces-left.h b/clang/test/Modules/Inputs/namespaces-left.h index 787fe753fba9..5badf62764b6 100644 --- a/clang/test/Modules/Inputs/namespaces-left.h +++ b/clang/test/Modules/Inputs/namespaces-left.h @@ -71,3 +71,5 @@ namespace N12 { } Foo *getFoo(); } + +namespace Empty {} diff --git a/clang/test/Modules/Inputs/namespaces-right.h b/clang/test/Modules/Inputs/namespaces-right.h index 77f54ead65ab..dd2ac33f9108 100644 --- a/clang/test/Modules/Inputs/namespaces-right.h +++ b/clang/test/Modules/Inputs/namespaces-right.h @@ -66,3 +66,5 @@ namespace N12 { } void consumeFoo(Foo*); } + +namespace Empty {} diff --git a/clang/test/Modules/Inputs/namespaces-top.h b/clang/test/Modules/Inputs/namespaces-top.h index 7bf5394f55be..006b53c8fd28 100644 --- a/clang/test/Modules/Inputs/namespaces-top.h +++ b/clang/test/Modules/Inputs/namespaces-top.h @@ -21,3 +21,5 @@ namespace N13 { namespace AddAndReexportBeforeImport { int S; } + +namespace Empty {}