Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why change warning level of a specific warning in C++?

Visual C++ features #pragma warning that among other things allows to change the warning level of a specific warning. Say warning X has level 4 by default, then after

#pragma warning( 3, X )

it will have level 3 from that point.

I understand why I would temporarily disable a warning, turn a warning into an error or turn on a waring that is off by default. But why would I change a warning level?

I mean warning level of a specific warning works together with the compiler "warning level" option /W, so I currently can't imagine a setup in which I would want to change a level of an individual warning since the warning being emitted or not will depend on the project settings.

What are real-life examples of when I really need to change a warning level of a specific warning in C++?

like image 891
sharptooth Avatar asked Jan 18 '23 09:01

sharptooth


2 Answers

When you want to run on level 3 or 4, but you want to see/not see a specific message, you can change its level. Sure, the pragma might have no effect if the warning level isn't what you think, but that's life with pragmas.

like image 174
Kate Gregory Avatar answered Jan 29 '23 06:01

Kate Gregory


It is much easier to take the one or two level 4 warnings you want detected and use the pragma to bring them into level 3 than it is to use /W4 and disable (/Wd####)the all the warnings you don't care about.

like image 33
IronMensan Avatar answered Jan 29 '23 06:01

IronMensan