================
@@ -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()) {
----------------
vbvictor wrote:

Imagine if we have:
```cpp
TypeRange(std::vector<int> b_ = {2, 2, 2}) : b(_b)
TypeRange(int count) : b(repeat(2, count))
```
So by default the container is not empty but has 3 elements, so this condition:
```cpp
if (TypeRange(1) == TypeRange(/*{2, 2, 2}*/)) 
```
is _not_ equivalent of
```cpp
if (TypeRange(1).empty())
```

Will the check correctly handle this case?



https://github.com/llvm/llvm-project/pull/154782
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to