https://github.com/flovent updated 
https://github.com/llvm/llvm-project/pull/154782

>From a2a7894dca6ec009974e5a25bfd11ce40a228d98 Mon Sep 17 00:00:00 2001
From: flovent <flb...@protonmail.com>
Date: Thu, 21 Aug 2025 23:06:31 +0800
Subject: [PATCH 1/2] [clang-tidy] Ignore default ctor with user provided
 argument in `readability-container-size-empty`

---
 .../readability/ContainerSizeEmptyCheck.cpp   |  2 +-
 clang-tools-extra/docs/ReleaseNotes.rst       |  3 ++-
 .../readability/container-size-empty.cpp      | 24 +++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index c4dc319f23c38..c5df94dae50b1 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -190,7 +190,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto WrongComparend =
       anyOf(stringLiteral(hasSize(0)),
             userDefinedLiteral(hasLiteral(stringLiteral(hasSize(0)))),
-            cxxConstructExpr(isDefaultConstruction()),
+            cxxConstructExpr(isDefaultConstruction(), argumentCountIs(0)),
             cxxUnresolvedConstructExpr(argumentCountIs(0)));
   // Match the object being compared.
   const auto STLArg =
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 388979d9577ba..adf1c039916ff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -211,7 +211,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-container-size-empty
   <clang-tidy/checks/readability/container-size-empty>` check by correctly
-  generating fix-it hints when size method is called from implicit ``this``.
+  generating fix-it hints when size method is called from implicit ``this``
+  and ignoring default constructors with user provided arguments.
 
 - Improved :doc:`readability-identifier-naming
   <clang-tidy/checks/readability/identifier-naming>` check by ignoring
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 b1e68672a3a9a..48a3ca1726f39 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
@@ -908,3 +908,27 @@ class foo : public std::string{
 };
 
 }
+
+namespace GH154762 {
+class TypeRange {
+  std::vector<int> b;
+
+public:
+  TypeRange(std::vector<int> b = {});
+  TypeRange(int);
+  bool operator==(const TypeRange& other) const;
+
+  size_t size() const {
+    return b.size();
+  }
+
+  bool empty() const {
+    return size() == 0;
+  }
+};
+
+void foo(std::vector<int> v) {
+  if (TypeRange(1) == TypeRange(v)) { // no warning
+  }
+}
+}

>From e62b59163de940a86e22234bd9d4bbb6922264ce Mon Sep 17 00:00:00 2001
From: flovent <flb...@protonmail.com>
Date: Fri, 22 Aug 2025 23:26:41 +0800
Subject: [PATCH 2/2] Remove isDefaultConstruction's use and matcher

---
 .../clang-tidy/readability/ContainerSizeEmptyCheck.cpp      | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index c5df94dae50b1..4c1bef6d0799a 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -89,10 +89,6 @@ AST_MATCHER(Expr, usedInBooleanContext) {
   return Result;
 }
 
-AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
-  return Node.getConstructor()->isDefaultConstructor();
-}
-
 AST_MATCHER(QualType, isIntegralType) {
   return Node->isIntegralType(Finder->getASTContext());
 }
@@ -190,7 +186,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto WrongComparend =
       anyOf(stringLiteral(hasSize(0)),
             userDefinedLiteral(hasLiteral(stringLiteral(hasSize(0)))),
-            cxxConstructExpr(isDefaultConstruction(), argumentCountIs(0)),
+            cxxConstructExpr(argumentCountIs(0)),
             cxxUnresolvedConstructExpr(argumentCountIs(0)));
   // Match the object being compared.
   const auto STLArg =

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to