How to identify the title that generates a warning?

I am sure many of you are familiar with this set of warnings. This is most of the time generated by the include file. The pragma push/disable/pop solution is pragma push/disable/pop , but defining a header is not a good task.

Does anyone know a way to identify the header other than a trial error?

 1>File1.cpp 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdio(49) : warning C4995: 'gets': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdio(53) : warning C4995: 'sprintf': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdio(56) : warning C4995: 'vsprintf': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring(22) : warning C4995: 'strcat': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring(23) : warning C4995: 'strcpy': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwchar(36) : warning C4995: 'swprintf': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwchar(37) : warning C4995: 'vswprintf': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwchar(39) : warning C4995: 'wcscat': name was marked as #pragma deprecated 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwchar(41) : warning C4995: 'wcscpy': name was marked as #pragma deprecated 1>Linking... 
+7
source share
7 answers

In my case, moving #include <strsafe.h> at the bottom of the list got rid of the warning without using additional compiler directives.

A good way to find out where #pragma deprecated is called is to go to the compiler settings in the Preprocessor section and set Generate a pre-processed file , for example, with line numbers (/ P), Rebuild, then open the * .i file and search for deprecated . Next will be the name of the offender.

I am using VS2003, so the dialogs may be slightly different for you.

+13
source

Standard files include security devices. Thus, you can explicitly include these files at the beginning of your own file, and this warning is disabled:

 #pragma warning(push) #pragma warning(disable: 4995) #include <cstdio> #include <cstring> #include <cwchar> #pragma warning(pop) // rest of your #includes 

This way, warnings will be turned off for headers where you know there are problems. This should be at the top of your code so that the headers are included for the first time in the section with the warning disabled.

+4
source

I would like to repeat what @Celdecea said.

Obviously, it would be nice if MS did what GCC did and indicated the included path (stack?) For the file, which I suppose is what you were looking for; Unfortunately, I could not find the compiler directive to do this, so grepping through the .i file was a painful but effective replacement.

I also found that my problem was with the addition of #includes after <strsafe.h> . Since my error list was (almost?) Identical to yours, I would not be surprised if this also solves your problem.

If not, or if you want to use the pragma push/disable/pop style pragma push/disable/pop , then it seems that @Greg has the best solution in a preventive order and explicitly defines the headers that hurt you.

+2
source

To add a Greg Hewgill message, I found a problem in the set and I did not suspect this file.

 #pragma warning(push) #pragma warning(disable: 4995) #include <set> #pragma warning(pop) 

Doing the above solves my problem.

0
source

Notes for #include strsafe.h include the line:

To use Strsafe's built-in functions, include the header file as shown here, following the #include instructions for all other header files.

MSDN offline help says:

Important: the include line for strsafe.h must follow all lines that include other headers.

Make sure that you just include in the cpp files and after all the other C ++ library header files, and the warnings go away.

Kevin

0
source

In Visual Studio 2010 (and possibly in other versions), set the C ++ / advanced 'show includes' parameter to Yes or add the / showIncludes command line parameter.

Then compile one file at a time and find the assembly output window for the alert number you are looking for, and it will show a tree of include files that generate this alert.

This method is useful for most build problems caused by included files.

EDIT: Make sure you turn off / showIncludes when the problem is fixed, as it may interfere with other compiler options (e.g. / MP (assembly with multiple processes) is disabled).

To suppress the warning, add the files containing the insult to the suppression block 4995, as suggested by Greg Huggil above. This can be either at the top of the source file, or in a precompiled header, or in the forced inclusion file included in the project (C ++ / Advanced / Forced Include File).

The specific problem with errors in CRT version 4995 is that they seem to be generated every time the code calls deprecated functions, even if warning 4995 was suppressed when deprecated functions were declared.

0
source

In my case for VS2008, these warnings came from #include <vector> (or some other std library). Microsoft seems to be unable to follow its advice.

The following issue has been fixed:

 #pragma warning(push) #pragma warning(disable: 4995) #include <vector> #pragma warning(pop) 

Just make sure you do this as early as possible in your inclusion.

0
source

All Articles