Add warn_unused_result to empty() on various containers.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 17:33:24 +0000 (17:33 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 17:33:24 +0000 (17:33 +0000)
empty() doesn't actually empty out the container, making this a common typo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190708 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DenseMap.h
include/llvm/ADT/SmallPtrSet.h
include/llvm/ADT/SmallVector.h
include/llvm/ADT/ilist.h

index 0b30161fa685b96aa6805560f6f3f1b6d63c4e8d..fac0b958ea2840fdd8dcc0b47c505dbb6a00917c 100644 (file)
@@ -64,7 +64,9 @@ public:
     return const_iterator(getBucketsEnd(), getBucketsEnd(), true);
   }
 
-  bool empty() const { return getNumEntries() == 0; }
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
+    return getNumEntries() == 0;
+  }
   unsigned size() const { return getNumEntries(); }
 
   /// Grow the densemap so that it has at least Size buckets. Does not shrink
index 8c7304197f34f3cd183a016d4d83d2e01909a859..bd0d8838ef02b8383daf061384b2254b2b503464 100644 (file)
@@ -71,7 +71,7 @@ protected:
   ~SmallPtrSetImpl();
 
 public:
-  bool empty() const { return size() == 0; }
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return size() == 0; }
   unsigned size() const { return NumElements; }
 
   void clear() {
index 0dc8904eaa38b9ba57ba2193a848e94b6a91e925..505aa8d8ae6184f09f4a0b36a5324d3946850f44 100644 (file)
@@ -53,7 +53,7 @@ public:
     return size_t((char*)CapacityX - (char*)BeginX);
   }
 
-  bool empty() const { return BeginX == EndX; }
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return BeginX == EndX; }
 };
 
 template <typename T, unsigned N> struct SmallVectorStorage;
index 71dab2ef551c7698b54c9cd6f4db6ded9e7ed20a..6aeaa91f1b1671db292ca0bfaf595c251ee9a97f 100644 (file)
@@ -382,7 +382,9 @@ public:
 
   // Miscellaneous inspection routines.
   size_type max_size() const { return size_type(-1); }
-  bool empty() const { return Head == 0 || Head == getTail(); }
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
+    return Head == 0 || Head == getTail();
+  }
 
   // Front and back accessor functions...
   reference front() {
@@ -534,7 +536,7 @@ public:
   // Functionality derived from other functions defined above...
   //
 
-  size_type size() const {
+  size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const {
     if (Head == 0) return 0; // Don't require construction of sentinel if empty.
     return std::distance(begin(), end());
   }