0

I get warnings after the MSVC-Output window says "Generating Code...".

1>Note: including file: D:\FOO\INC\ippcc.h
1>Generating Code...
1>d:\FOO\inc\ipinctrlimpl.h(130): warning C4701: potentially uninitialized local variable 'hResult' used
1>d:\FOO\inc\iwatchdogimpl.h(158): warning C4702: unreachable code
1>   Creating library ..\..\LIB/FOO.lib and object ..\..\LIB/FOO.exp
1>FOO.vcxproj -> D:\FOO\FOO.dll
1>Done building project "FOO.vcxproj".

How can I supress these warnings without disabling them for the whole solution? I cannot touch the code myself, so fixing them is no option.

According to this post, the compiler is generating the machine code at that point. How is it even possible that these warnings are generated then? After all, the basic compilation is already done.

UPDATE:

Setting the global warning level to /W3 in the project settings rather than /W4 prevents those warnings (because they are Level 4 warnings).

Instead of globally setting /W3, I can also explicitly disable the warnings locally for the critical includes:

#pragma warning(push)
#pragma warning(disable : 4701 4702)
#include "CriticalInclude.h"
#pragma warning(pop)

But here comes the weird thing: Locally setting /W3 (or even /W1) via

#pragma warning(push, 3)
#include "CriticalInclude.h"
#pragma warning(pop)

does not prevent those warnings. Why?

It seems like pushing and popping a warning disable is somehow treated differently than pushing a new warning level.

STiFU
  • 303
  • 2
  • 8
  • Are `ipinctrlimpl.h` and `iwatchdogimpl.h` your own header files? If so you should fix the problem instead of suppressing it. – NathanOliver Nov 20 '18 at 14:27
  • Those are templates of our company's kernel code, which I am not to touch. – STiFU Nov 20 '18 at 14:31
  • It is quite normal for the compiler to discover these problems at the point it starts generating code. The parser can't know yet what the optimizer is going to do. Keep in mind that, although they appear in .h file, they may easily be generated by your own code. These are inline functions so the arguments you pass matter a lot. – Hans Passant Nov 20 '18 at 16:14

2 Answers2

2

You should not be suppressing warnings, but dealing with them.
If you have unreachable code, why have it there?
Make sure you initialise variables.

The basic compilation isn't done at that stage according to this answer:
VC++ 'Generating Code', what does it mean?

Also, if those aren't your files, you should raise an issue with the developer. But this is temporary
How to suppress warnings in external headers in Visual C++

Reece Ward
  • 213
  • 2
  • 9
  • I know about pragma warning (push). I use that frequently to suppress other peoples warnings before including their headers. I already put this pragma around the inclusion of these critical headers, but the warning still occurs. Hence, Visual Studio must be doing something somewhere, that is somehow out of my control. – STiFU Nov 20 '18 at 16:24
  • What do you mean there is no header. Maybe something else is including it that you aren't seeing – Reece Ward Nov 20 '18 at 16:26
  • I had edited my above comment while you were already answering, sorry. I enabled "Show Includes", tracked down every instance of the critical includes and disabled warnings for that branch of inclusions. I still get the warnings. – STiFU Nov 20 '18 at 16:33
  • https://msdn.microsoft.com/en-us/library/2c8f766e.aspx Make sure you are providing the correct level, maybe edit your post to show your usage – Reece Ward Nov 20 '18 at 16:38
  • According to that MSDN page, the lowest supported value for the pragma is 1 instead of 0, which I have used in my poject, see my main post. However, I have found numerous sources on the web, stating that you can put the 0 to disable warnings completely. – STiFU Nov 20 '18 at 17:03
  • Please note the update on my main post. I did some further experiments... – STiFU Nov 21 '18 at 09:59
0

So, as of my previous Update, locally reducing the warning level does not seem to carry on to the "Generating Code"-Stage.

#pragma warning(push, 1)
#include "CriticalInclude.h"
#pragma warning(pop)

However, explicitly disabling these warnings locally does have an effect on the generating code stage:

#pragma warning(push)
#pragma warning(disable : 4701 4702)
#include "CriticalInclude.h"
#pragma warning(pop)

To me, this seems almost like a bug in the compiler.

STiFU
  • 303
  • 2
  • 8
  • Just FYI, I have now discovered that reducing the warning level locally via "warning push" does not at all work as expected. In my solutions, warnings outside the push/pop fence where suppressed, which should not have happened!!! Maybe a bug in the preprocessor? I don't know. Why I DO know is that explicitly disabling certain warnings locally inside the push/pop works as expected. – STiFU Dec 03 '18 at 14:27