PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] How to suppress a warning in clang++?

 April 28, 2022     clang++, warnings     No comments   

Issue

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?


Solution

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.



Answered By - Mike Kinghan
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing