Xeo
Xeo

Reputation: 131799

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.

Upvotes: 5

Views: 259

Answers (1)

Pubby
Pubby

Reputation: 53047

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)

Upvotes: 2

Related Questions