73 lines · cpp
1// RUN: %check_clang_tidy %s hicpp-ignored-remove-result %t2// RUN: %check_clang_tidy -check-suffixes=NOCAST %s hicpp-ignored-remove-result %t -- -config='{CheckOptions: {hicpp-ignored-remove-result.AllowCastToVoid: false}}'3 4namespace std {5 6template <typename ForwardIt, typename T>7ForwardIt remove(ForwardIt, ForwardIt, const T &);8 9template <typename ForwardIt, typename UnaryPredicate>10ForwardIt remove_if(ForwardIt, ForwardIt, UnaryPredicate);11 12template <typename ForwardIt>13ForwardIt unique(ForwardIt, ForwardIt);14 15template <class InputIt, class T>16InputIt find(InputIt, InputIt, const T&);17 18struct unique_disposable {19 void* release();20};21 22class error_code {23};24 25} // namespace std26 27std::error_code errorFunc() {28 return std::error_code();29}30 31void warning() {32 std::remove(nullptr, nullptr, 1);33 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors34 // CHECK-MESSAGES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning35 // CHECK-MESSAGES-NOCAST: [[@LINE-3]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors36 37 std::remove_if(nullptr, nullptr, nullptr);38 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors39 // CHECK-MESSAGES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning40 // CHECK-MESSAGES-NOCAST: [[@LINE-3]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors41 42 std::unique(nullptr, nullptr);43 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors44 // CHECK-MESSAGES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning45 // CHECK-MESSAGES-NOCAST: [[@LINE-3]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors46}47 48void optionalWarning() {49 // No warning unless AllowCastToVoid=false50 (void)std::remove(nullptr, nullptr, 1);51 // CHECK-MESSAGES-NOCAST: [[@LINE-1]]:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors52}53 54void noWarning() {55 56 auto RemoveRetval = std::remove(nullptr, nullptr, 1);57 58 auto RemoveIfRetval = std::remove_if(nullptr, nullptr, nullptr);59 60 auto UniqueRetval = std::unique(nullptr, nullptr);61 62 // Verify that other checks in the baseclass are not used.63 // - no warning on std::find since the checker overrides64 // bugprone-unused-return-value's checked functions.65 std::find(nullptr, nullptr, 1);66 // - no warning on return types since the checker disable67 // bugprone-unused-return-value's checked return types.68 errorFunc();69 (void) errorFunc();70 71 std::unique_disposable{}.release();72}73