Index: lib/Sema/SemaDeclCXX.cpp =================================================================== --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -8912,6 +8912,11 @@ if (IsInline != PrevNS->isInline()) DiagnoseNamespaceInlineMismatch(*this, NamespaceLoc, Loc, II, &IsInline, PrevNS); + if (II->isStr("std") && PrevNS->isStdNamespace() && + PrevNS != getStdNamespace()) { + PrevNS = getStdNamespace(); + IsStd = true; + } } else if (PrevDecl) { // This is an invalid name redefinition. Diag(Loc, diag::err_redefinition_different_kind) @@ -9206,6 +9211,8 @@ &PP.getIdentifierTable().get("std"), /*PrevDecl=*/nullptr); getStdNamespace()->setImplicit(true); + if (getLangOpts().Modules) + getStdNamespace()->setHasExternalVisibleStorage(true); } return getStdNamespace(); Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -7533,8 +7533,15 @@ return false; auto It = Lookups.find(DC); - if (It == Lookups.end()) - return false; + if (It == Lookups.end()) { + if (getContext().getLangOpts().Modules && DC->isStdNamespace()) { + for (auto StdIt = Lookups.begin(); StdIt != Lookups.end(); StdIt++) + if (StdIt->first->isStdNamespace()) + It = StdIt; + } + if (It == Lookups.end()) + return false; + } Deserializing LookupResults(this); Index: test/Modules/Inputs/mod-virtual-destructor-bug-two/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/mod-virtual-destructor-bug-two/a.h @@ -0,0 +1 @@ +namespace std { class type_info; } Index: test/Modules/Inputs/mod-virtual-destructor-bug-two/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/mod-virtual-destructor-bug-two/module.modulemap @@ -0,0 +1,3 @@ +module "a.h" { + header "a.h" +} Index: test/Modules/Inputs/mod-virtual-destructor-bug/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/mod-virtual-destructor-bug/a.h @@ -0,0 +1 @@ +namespace std {} Index: test/Modules/Inputs/mod-virtual-destructor-bug/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/mod-virtual-destructor-bug/module.modulemap @@ -0,0 +1,3 @@ +module "a.h" { + header "a.h" +} Index: test/Modules/mod-virtual-destructor-bug-two.cpp =================================================================== --- /dev/null +++ test/Modules/mod-virtual-destructor-bug-two.cpp @@ -0,0 +1,12 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -std=c++17 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/mod-virtual-destructor-bug-two %s -verify + +class A { + virtual ~A() {} +}; + +#include "a.h" + +void foo() { + typeid(foo); // expected-warning {{expression result unused}} +} Index: test/Modules/mod-virtual-destructor-bug.cpp =================================================================== --- /dev/null +++ test/Modules/mod-virtual-destructor-bug.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -std=c++17 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/mod-virtual-destructor-bug %s -verify + +class A { + virtual ~A() {} +}; + +#include "a.h" + +namespace std { class type_info; } + +void foo() { + typeid(foo); // expected-warning {{expression result unused}} +}