I compiled the following c++ program:
int main() { 2==3; }
with:
clang++-5.0 -std=c++17 -Wunused-comparison prog.cpp
and got the warning:
warning: equality comparison result unused [-Wunused-comparison]
2==3;
~^~~
... so, probably this is not the correct way to suppress a warning in CLANG.
In the clang manual, this part is a "TODO".
What is the correct command-line flag to disable a warning?
Using _Pragma to suppress the warning. Using #pragma to suppress the warning. Using command line options to suppress the warning.
To suppress this warning use the unused attribute (see Variable Attributes). This warning is also enabled by -Wunused , which is enabled by -Wall . Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall .
Maybe you can look for CFLAGS options in Makefile and remove the -Werror flag. The Werror flag will make all warnings into errors. Show activity on this post.
In the clang diagnostic that you get from:
$ cat main.cpp
int main()
{
2==3;
return 0;
}
$ clang++ -c main.cpp
main.cpp:3:6: warning: equality comparison result unused [-Wunused-comparison]
2==3;
~^~~
1 warning generated.
the bracketed:
-Wunused-comparison
tells you that -Wunused-comparison
is the enabled warning (in this case enabled by default) that was responsible for the diagnostic. So to suppress the diagnostic you explicitly disable that warning with the matching -Wno-...
flag:
$ clang++ -c -Wno-unused-comparison main.cpp; echo Done
Done
The same applies for GCC.
In general, it is reckless to suppress warnings. One should rather enable them generously - -Wall -Wextra [-pedantic]
- and then fix offending code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With