https://github.com/frederic-tingaud-sonarsource updated https://github.com/llvm/llvm-project/pull/81776
>From c12b2e26ad7a114aff09b89c75178d4ab7890a20 Mon Sep 17 00:00:00 2001 From: Fred Tingaud <frederic.ting...@sonarsource.com> Date: Wed, 14 Feb 2024 19:40:29 +0100 Subject: [PATCH 1/2] [clang] Fix isInStdNamespace for Decl flagged extern c++ --- clang/lib/AST/DeclBase.cpp | 3 +++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 8163f9bdaf8d97..4cfe9ed3340735 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -402,6 +402,9 @@ bool Decl::isInAnonymousNamespace() const { bool Decl::isInStdNamespace() const { const DeclContext *DC = getDeclContext(); + while (auto const LD = dyn_cast_or_null<LinkageSpecDecl>(DC)) { + DC = LD->getDeclContext(); + } return DC && DC->isStdNamespace(); } diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index edcdae4559d970..b75da7bc1ed069 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) { >From 3d37a1b59032889115ef1c9e7039c65d3c6ff830 Mon Sep 17 00:00:00 2001 From: Fred Tingaud <frederic.ting...@sonarsource.com> Date: Thu, 15 Feb 2024 10:18:46 +0100 Subject: [PATCH 2/2] Add ReleaseNotes entry. --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6cf48d63dd512e..db3dc724997286 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -308,6 +308,8 @@ Floating Point Support in Clang AST Matchers ------------ +- ``isInStdNamespace`` now supports Decl declared with ``extern "C++"``. + clang-format ------------ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits