diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b5e6eae9f1bf7..5a19c2ea36bdf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -327,6 +327,8 @@ Fixed Point Support in Clang AST Matchers ------------ +- ``isInStdNamespace`` now supports Decl declared with ``extern "C++"``. + clang-format ------------ diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 8163f9bdaf8d9..10fe8bb97ce66 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -402,7 +402,7 @@ bool Decl::isInAnonymousNamespace() const { bool Decl::isInStdNamespace() const { const DeclContext *DC = getDeclContext(); - return DC && DC->isStdNamespace(); + return DC && DC->getNonTransparentContext()->isStdNamespace(); } bool Decl::isFileContextDecl() const { diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index edcdae4559d97..b75da7bc1ed06 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -3637,6 +3637,11 @@ TEST_P(ASTMatchersTest, InStdNamespace) { " class vector {};" "}", cxxRecordDecl(hasName("vector"), isInStdNamespace()))); + + EXPECT_TRUE(matches("namespace std {" + " extern \"C++\" class vector {};" + "}", + cxxRecordDecl(hasName("vector"), isInStdNamespace()))); } TEST_P(ASTMatchersTest, InAnonymousNamespace) {