Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warnings that will consistently get triggered across different compilers?

After writing an answer to this question which displays the solution at compile time with an error, I wondered if it was possible to get a warning instead and finish compilation (as is actually specified in the question).

While diagnostics in general are compiler-dependant, it's pretty obvious for some code that an error will get triggered (such as accessing a non-existent member or trying to instantiate an object of incomplete type).

The same can't be said for warnings though, since these tend to differ a great deal between compilers. Even though it's reasonable to assume that warnings triggered with GCC will also get triggered with Clang, the same can not be said for Visual C++.

Question:
Which warnings, if any, will consistently get triggered on all three mentioned compilers?

/W3 on VC++ and -Wall on GCC & Clang may be assumed.


Note that this is not only useful for that question, but may be useful for triggering a warning for user-defined messages aswell.

like image 454
Xeo Avatar asked Nov 05 '22 08:11

Xeo


1 Answers

This should work on MSVC, GCC, and Clang:

#pragma message("hello world")

Not very useful, but still works.

These picked up warnings too:

  • unused variable
  • unused label
  • large values e.g. (1 << 128)
like image 180
Pubby Avatar answered Nov 10 '22 16:11

Pubby