[clang-tools-extra] [clang-tidy] Ignore default ctor with user provided argument in `readability-container-size-empty` (PR #154782)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 23 05:20:51 PDT 2025
================
@@ -908,3 +908,37 @@ 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
+ }
+
+ if (TypeRange(1) == TypeRange()) {
----------------
flovent wrote:
I don't think they are FPs, when calling a non-default ctor or default ctor with user-provided argument, it means this container is not empty, and `TypeRange()` should have zero size since it's default constructed, so it's reasonable to give a suggestion of using `empty` here.
https://github.com/llvm/llvm-project/pull/154782
More information about the cfe-commits
mailing list