https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/214704

None

>From fbc5ff7baa2715b72e7e0ed26bc23e1d329b56a2 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Fri, 7 Aug 2026 19:11:14 +0800
Subject: [PATCH] [clang-tidy] Fix a crash in
 bugprone-std-namespace-modification

---
 .../StdNamespaceModificationCheck.cpp         | 19 +++++++++++++++----
 clang-tools-extra/docs/ReleaseNotes.rst       |  4 ++++
 .../std-namespace-modification-no-crash.cpp   | 10 ++++++++++
 3 files changed, 29 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification-no-crash.cpp

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
index a623ed690697b..241971a8a4ae8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
@@ -34,6 +34,19 @@ AST_POLYMORPHIC_MATCHER_P(
                              Builder) != Args.end();
 }
 
+AST_MATCHER(NamedDecl, isInStdOrPosixNamespace) {
+  for (const DeclContext *DC = Node.getDeclContext(); DC;
+       DC = DC->getParent()) {
+    if (DC->isStdNamespace())
+      return true;
+
+    const auto *NS = dyn_cast<NamespaceDecl>(DC);
+    if (NS && !isa<NamespaceDecl>(NS->getParent()) && NS->getName() == "posix")
+      return true;
+  }
+  return false;
+}
+
 } // namespace
 
 namespace clang::tidy::bugprone {
@@ -43,10 +56,8 @@ void 
StdNamespaceModificationCheck::registerMatchers(MatchFinder *Finder) {
       hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
                                    unless(hasParent(namespaceDecl())))
                          .bind("nmspc"));
-  const auto UserDefinedDecl =
-      namedDecl(anyOf(classTemplateDecl(), tagDecl()),
-                hasAncestor(namespaceDecl(hasAnyName("std", "posix"),
-                                          
unless(hasParent(namespaceDecl())))));
+  const auto UserDefinedDecl = namedDecl(anyOf(classTemplateDecl(), tagDecl()),
+                                         isInStdOrPosixNamespace());
   const auto UserDefinedType = qualType(hasUnqualifiedDesugaredType(anyOf(
       tagType(unless(hasDeclaration(UserDefinedDecl))),
       templateSpecializationType(unless(hasDeclaration(UserDefinedDecl))))));
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0dcf2ea1f21c7..ed462bc7339fc 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,10 @@ New check aliases
 Changes in existing checks
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+- Fixed a crash in :doc:`bugprone-std-namespace-modification
+  <clang-tidy/checks/bugprone/std-namespace-modification>` when checking
+  lambda closure types used as template arguments.
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   <clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check by treating
   ``std::array`` the same as built-in arrays when `IgnoreArrays` option is 
enabled.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification-no-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification-no-crash.cpp
new file mode 100644
index 0000000000000..7921e8a40605a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification-no-crash.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy -std=c++20-or-later -expect-clang-tidy-error %s 
bugprone-std-namespace-modification %t
+
+template <class A, class B> struct O : A, B {};
+template <class T> void f() {
+  auto a = [](auto) {};
+  auto b = [](auto) -> decltype(({ })) {};
+  O(a, b)(T{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: error: member 'operator()' found in 
multiple base classes of different types
+}
+template void f<int>();

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to