[PATCH] SemaLookup.cpp wrong boolean test

Alp Toker alp at nuanti.com
Sat Nov 23 15:17:07 PST 2013


On 01/10/2013 19:25, Yaron Keren wrote:
> In SemaLookup.cpp, line 4102 the test is somewhat wrong, as count 
> (surprisingly given its name) return a boolean and not an integer.
>
> locs->second.count(TypoName.getLoc()) > 0)
>
> A patch is attached.

Aaron fixed this in r192043.

>
> I think this count function should be renamed to exists to better 
> reflect its function.

For better or worse count() is what STL templates expect, so best not to 
change that.

It could however return an unsigned integral type, and I've attached a 
patch to do that, using unsigned rather than size_t to match 
SmallSet::size(). LGTY?

Also, MSVC diags on inequality comparison with bool, wonder if that 
would be nice to have in clang (in fact I thought this kind of 
comparison range check already existed, weird.)

Alp.




>
> Yaron
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-- 
http://www.nuanti.com
the browser experts

-------------- next part --------------
diff --git a/include/llvm/ADT/SmallSet.h b/include/llvm/ADT/SmallSet.h
index ecd3843..f9eb126 100644
--- a/include/llvm/ADT/SmallSet.h
+++ b/include/llvm/ADT/SmallSet.h
@@ -47,13 +47,13 @@ public:
     return isSmall() ? Vector.size() : Set.size();
   }
 
-  /// count - Return true if the element is in the set.
-  bool count(const T &V) const {
+  /// count - Return 1 if the element is in the set, otherwise 0.
+  unsigned count(const T &V) const {
     if (isSmall()) {
       // Since the collection is small, just do a linear search.
-      return vfind(V) != Vector.end();
+      return vfind(V) == Vector.end() ? 0 : 1;
     } else {
-      return Set.count(V);
+      return Set.count(V) ? 1 : 0;
     }
   }
 


More information about the cfe-commits mailing list