https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88738
--- Comment #6 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> --- (In reply to Martin Sebor from comment #5) > If it did we could have GCC apply it implicitly to > all such functions or operators defined in namespace std, and provide a new > attribute to disable it in the cases where it might not be appropriate (say > no_warn_unused_result). I looked at what clang does and it's very simplistic. The code below produces the output shows below. I.e., they use the warning for all comparison operators regardless of - namespace - return value - member function or not - const-ness of operators - visible side effects Nevertheless people use the compiler without complaining, at least visibly. $ clang++ -c -O -Wall u.cc u.cc:26:5: warning: equality comparison result unused [-Wunused-comparison] l == r; ~~^~~~ u.cc:26:5: note: use '=' to turn this equality comparison into an assignment l == r; ^~ = u.cc:31:5: warning: inequality comparison result unused [-Wunused-comparison] l != r; ~~^~~~ u.cc:31:5: note: use '|=' to turn this inequality comparison into an or-assignment l != r; ^~ |= u.cc:36:5: warning: relational comparison result unused [-Wunused-comparison] l <= r; ~~^~~~ u.cc:41:5: warning: relational comparison result unused [-Wunused-comparison] l >= r; ~~^~~~ u.cc:46:5: warning: relational comparison result unused [-Wunused-comparison] l < r; ~~^~~ 5 warnings generated. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct foo { int a; foo(int) : a(42) {} auto operator==(const foo& o) const { return a == o.a; } auto operator!=(foo& o) { return a == o.a; } }; auto operator<=(const foo& l, const foo& r) { return l.a == r.a; } auto operator>=(foo& l, foo& r) { l.a |= 1; return l.a == r.a; } int operator<(foo& l, foo& r) { return l.a == r.a ? 0 : l.a < r.a ? -1 : 1; } auto f1(foo& l, foo& r) { l == r; } auto f2(foo& l, foo& r) { l != r; } auto f3(foo& l, foo& r) { l <= r; } auto f4(foo& l, foo& r) { l >= r; } auto f5(foo& l, foo& r) { l < r; }