[cfe-dev] Incomplete set of warnings in clang

Marshall Clow mclow.lists at gmail.com
Mon Mar 10 11:13:50 PDT 2014


As I was working on a libc++ issue (
2263. Comparing iterators and allocator pointers with different const-character), if anyone cares, I wrote the following test program:

#include <string>

int main() {
  std::string::iterator it;
  std::string::const_iterator cit;

  it == cit;
  it != cit;
  it < cit;
  it <= cit;
  it > cit;
  it >= cit;
}

I wanted to make sure that these were all legal comparisons using libc++ (and they are).
I kind of expected some compiler warnings about “unused results” or something.

What I didn’t expect was to get _two_ warnings. I figured either zero or some multiple of six.

Apparently clang doesn’t like it if you don’t use the result of == or !=, but is perfectly happy with ignoring the results of >, >=, <, <=.

Why is that?

— Marshall





More information about the cfe-dev mailing list