<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 13, 2013 at 10:33 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Fri Sep 13 12:33:24 2013<br>
New Revision: 190708<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=190708&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=190708&view=rev</a><br>
Log:<br>
Add warn_unused_result to empty() on various containers.<br></blockquote><div><br></div><div>This seems tedious (though I appreciate the work) - how bad would it be if Clang assumed const member functions with no parameters were warn_unused_result?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
empty() doesn't actually empty out the container, making this a common typo.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/DenseMap.h<br>
    llvm/trunk/include/llvm/ADT/SmallPtrSet.h<br>
    llvm/trunk/include/llvm/ADT/SmallVector.h<br>
    llvm/trunk/include/llvm/ADT/ilist.h<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/DenseMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=190708&r1=190707&r2=190708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=190708&r1=190707&r2=190708&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Fri Sep 13 12:33:24 2013<br>
@@ -64,7 +64,9 @@ public:<br>
     return const_iterator(getBucketsEnd(), getBucketsEnd(), true);<br>
   }<br>
<br>
-  bool empty() const { return getNumEntries() == 0; }<br>
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {<br>
+    return getNumEntries() == 0;<br>
+  }<br>
   unsigned size() const { return getNumEntries(); }<br>
<br>
   /// Grow the densemap so that it has at least Size buckets. Does not shrink<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/SmallPtrSet.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallPtrSet.h?rev=190708&r1=190707&r2=190708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallPtrSet.h?rev=190708&r1=190707&r2=190708&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/SmallPtrSet.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/SmallPtrSet.h Fri Sep 13 12:33:24 2013<br>
@@ -71,7 +71,7 @@ protected:<br>
   ~SmallPtrSetImpl();<br>
<br>
 public:<br>
-  bool empty() const { return size() == 0; }<br>
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return size() == 0; }<br>
   unsigned size() const { return NumElements; }<br>
<br>
   void clear() {<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=190708&r1=190707&r2=190708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=190708&r1=190707&r2=190708&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Fri Sep 13 12:33:24 2013<br>
@@ -53,7 +53,7 @@ public:<br>
     return size_t((char*)CapacityX - (char*)BeginX);<br>
   }<br>
<br>
-  bool empty() const { return BeginX == EndX; }<br>
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return BeginX == EndX; }<br>
 };<br>
<br>
 template <typename T, unsigned N> struct SmallVectorStorage;<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/ilist.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=190708&r1=190707&r2=190708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=190708&r1=190707&r2=190708&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/ilist.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/ilist.h Fri Sep 13 12:33:24 2013<br>
@@ -382,7 +382,9 @@ public:<br>
<br>
   // Miscellaneous inspection routines.<br>
   size_type max_size() const { return size_type(-1); }<br>
-  bool empty() const { return Head == 0 || Head == getTail(); }<br>
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {<br>
+    return Head == 0 || Head == getTail();<br>
+  }<br>
<br>
   // Front and back accessor functions...<br>
   reference front() {<br>
@@ -534,7 +536,7 @@ public:<br>
   // Functionality derived from other functions defined above...<br>
   //<br>
<br>
-  size_type size() const {<br>
+  size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const {<br>
     if (Head == 0) return 0; // Don't require construction of sentinel if empty.<br>
     return std::distance(begin(), end());<br>
   }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>