https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62182
Bug ID: 62182
Summary: New warning wished: operator== and "equality
comparison result unused
[-Wunused-comparison]"/-Wunsed-value
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: mpolacek at gcc dot gnu.org
For a simple:
int i;
i == 5;
GCC diagnoses (but warning is enabled not by default):
warning: statement with no effect [-Wunused-value]
i == 7;
CLANG does the same (warning enabled by default):
warning: equality comparison result unused [-Wunused-comparison]
i == 7;
~~^~~~
note: use '=' to turn this equality comparison into an assignment
i == 7;
^~
=
However, in our code C++ code, we used an operator==. In that case, GCC doesn't
warn while Clang does (by default):
foo.cc:6:7: warning: equality comparison result unused [-Wunused-comparison]
str == "bar";
~~~~^~~~~~~~
foo.cc:6:7: note: use '=' to turn this equality comparison into an assignment
str == "bar";
^~
=
C++ test case:
#include <stdio.h>
#include <string>
int main() {
std::string str("init");
str == "bar";
printf("%s\n", str.c_str());
return 0;
}