diff --git a/libcxx/test/support/test_comparisons.h b/libcxx/test/support/test_comparisons.h --- a/libcxx/test/support/test_comparisons.h +++ b/libcxx/test/support/test_comparisons.h @@ -30,7 +30,7 @@ // Test all six comparison operations for sanity template -TEST_CONSTEXPR_CXX14 bool testComparisons(const T& t1, const U& t2, bool isEqual, bool isLess) +TEST_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 -TEST_CONSTEXPR_CXX14 bool testComparisonsValues(Param val1, Param val2) +TEST_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 -constexpr bool testOrder(const T& t1, const U& t2, Order order) { +TEST_NODISCARD constexpr bool testOrder(const T& t1, const U& t2, Order order) { bool equal = order == Order::equivalent; bool less = order == Order::less; @@ -145,7 +145,7 @@ } template -constexpr bool testOrderValues(Param val1, Param val2) { +TEST_NODISCARD constexpr bool testOrderValues(Param val1, Param val2) { return testOrder(T(val1), T(val2), val1 <=> val2); } @@ -153,7 +153,7 @@ // Test all two comparison operations for sanity template -TEST_CONSTEXPR_CXX14 bool testEquality(const T& t1, const U& t2, bool isEqual) +TEST_NODISCARD TEST_CONSTEXPR_CXX14 bool testEquality(const T& t1, const U& t2, bool isEqual) { if (isEqual) { @@ -175,7 +175,7 @@ // Easy call when you can init from something already comparable. template -TEST_CONSTEXPR_CXX14 bool testEqualityValues(Param val1, Param val2) +TEST_NODISCARD TEST_CONSTEXPR_CXX14 bool testEqualityValues(Param val1, Param val2) { const bool isEqual = val1 == val2; diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -235,6 +235,12 @@ #define LIBCPP_ONLY(...) static_assert(true, "") #endif +#if __has_cpp_attribute(nodiscard) +# define TEST_NODISCARD [[nodiscard]] +#else +# define TEST_NODISCARD +#endif + #define TEST_IGNORE_NODISCARD (void) namespace test_macros_detail {