[clang-tools-extra] e54f838 - [clang-tidy] Avoid assert failure on non-identifier names in `readability-container-size-empty` (#181557)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 15 20:22:03 PST 2026
Author: mitchell
Date: 2026-02-16T12:21:58+08:00
New Revision: e54f838bd59abed2b35ad8c08ca5de3cb99f59cb
URL: https://github.com/llvm/llvm-project/commit/e54f838bd59abed2b35ad8c08ca5de3cb99f59cb
DIFF: https://github.com/llvm/llvm-project/commit/e54f838bd59abed2b35ad8c08ca5de3cb99f59cb.diff
LOG: [clang-tidy] Avoid assert failure on non-identifier names in `readability-container-size-empty` (#181557)
Closes https://github.com/llvm/llvm-project/issues/181552
Added:
Modified:
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index 073fdce5018bf..f171cd0f44af4 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -116,11 +116,15 @@ AST_POLYMORPHIC_MATCHER_P(
matchMemberName,
AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, CXXDependentScopeMemberExpr),
std::string, MemberName) {
- if (const auto *E = dyn_cast<MemberExpr>(&Node))
- return E->getMemberDecl()->getName() == MemberName;
+ if (const auto *E = dyn_cast<MemberExpr>(&Node)) {
+ const IdentifierInfo *II = E->getMemberDecl()->getIdentifier();
+ return II && II->getName() == MemberName;
+ }
- if (const auto *E = dyn_cast<CXXDependentScopeMemberExpr>(&Node))
- return E->getMember().getAsString() == MemberName;
+ if (const auto *E = dyn_cast<CXXDependentScopeMemberExpr>(&Node)) {
+ const IdentifierInfo *II = E->getMember().getAsIdentifierInfo();
+ return II && II->getName() == MemberName;
+ }
return false;
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 0c487524390e3..ee057d9bf0444 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -222,6 +222,10 @@ Changes in existing checks
<clang-tidy/checks/performance/move-const-arg>` check by avoiding false
positives on trivially copyable types with a non-public copy constructor.
+- Improved :doc:`readability-container-size-empty
+ <clang-tidy/checks/readability/container-size-empty>` check by fixing a crash
+ when a member expression has a non-identifier name.
+
- Improved :doc:`readability-enum-initial-value
<clang-tidy/checks/readability/enum-initial-value>` check: the warning message
now uses separate note diagnostics for each uninitialized enumerator, making
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 7844275c3a960..aacb74306edc7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -985,3 +985,18 @@ class ReportInContainerNonEmptyMethodCompare {
}
}
};
+
+namespace GH181552 {
+struct DestructorContainer {
+ unsigned long size() const;
+ bool empty() const;
+ ~DestructorContainer();
+};
+
+struct DestructorUser {
+ DestructorContainer Indexes;
+ ~DestructorUser() {
+ Indexes.~DestructorContainer();
+ }
+};
+}
More information about the cfe-commits
mailing list