[libcxx-commits] [PATCH] D131364: [libc++][test] Mark `test_comparisons.h` helpers as nodiscard

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 7 10:36:10 PDT 2022


avogelsgesang created this revision.
avogelsgesang added reviewers: Mordante, philnik, ldionne, mumbleskates.
Herald added a project: All.
avogelsgesang requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

I accidentally wrote `testComparisons(...)` instead of
`assert(testComparisons(...)`. This compiled without issues, but
did not provide the intended test coverage. By adding a `nodiscard`,
we can make sure that the compiler catches such mistakes for us.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131364

Files:
  libcxx/test/support/test_comparisons.h


Index: libcxx/test/support/test_comparisons.h
===================================================================
--- libcxx/test/support/test_comparisons.h
+++ libcxx/test/support/test_comparisons.h
@@ -30,7 +30,7 @@
 
 //  Test all six comparison operations for sanity
 template <class T, class U = T>
-TEST_CONSTEXPR_CXX14 bool testComparisons(const T& t1, const U& t2, bool isEqual, bool isLess)
+_LIBCPP_NODISCARD TEST_CONSTEXPR_CXX14 bool testComparisons(const T& t1, const U& t2, bool isEqual, bool isLess)
 {
     assert(!(isEqual && isLess) && "isEqual and isLess cannot be both true");
     if (isEqual)
@@ -84,7 +84,7 @@
 
 //  Easy call when you can init from something already comparable.
 template <class T, class Param>
-TEST_CONSTEXPR_CXX14 bool testComparisonsValues(Param val1, Param val2)
+_LIBCPP_NODISCARD TEST_CONSTEXPR_CXX14 bool testComparisonsValues(Param val1, Param val2)
 {
     const bool isEqual = val1 == val2;
     const bool isLess  = val1  < val2;
@@ -137,7 +137,7 @@
 }
 
 template <class Order, class T, class U = T>
-constexpr bool testOrder(const T& t1, const U& t2, Order order) {
+_LIBCPP_NODISCARD constexpr bool testOrder(const T& t1, const U& t2, Order order) {
     bool equal = order == Order::equivalent;
     if constexpr (std::same_as<Order, std::strong_ordering>)
         equal |= order == Order::equal;
@@ -148,7 +148,7 @@
 }
 
 template <class T, class Param>
-constexpr bool testOrderValues(Param val1, Param val2) {
+_LIBCPP_NODISCARD constexpr bool testOrderValues(Param val1, Param val2) {
   return testOrder(T(val1), T(val2), val1 <=> val2);
 }
 
@@ -156,7 +156,7 @@
 
 //  Test all two comparison operations for sanity
 template <class T, class U = T>
-TEST_CONSTEXPR_CXX14 bool testEquality(const T& t1, const U& t2, bool isEqual)
+_LIBCPP_NODISCARD TEST_CONSTEXPR_CXX14 bool testEquality(const T& t1, const U& t2, bool isEqual)
 {
     if (isEqual)
         {
@@ -178,7 +178,7 @@
 
 //  Easy call when you can init from something already comparable.
 template <class T, class Param>
-TEST_CONSTEXPR_CXX14 bool testEqualityValues(Param val1, Param val2)
+_LIBCPP_NODISCARD TEST_CONSTEXPR_CXX14 bool testEqualityValues(Param val1, Param val2)
 {
     const bool isEqual = val1 == val2;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131364.450651.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220807/df28facb/attachment.bin>


More information about the libcxx-commits mailing list