Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings from internal Visual Studio files

I set the warning level to EnableAllWarnings (/Wall) in Visual Studio 2012 and in this simple program:

#include "math.h"

int main() {
    return 0;
}

When I compile, I got several warnings like:

1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\math.h(161): warning C4514: 'hypot' : unreferenced inline function has been removed

If I replace the "math.h" to "string.h" I continue receiving warnings about the string.h and so on.

Does anyone know how to remove these warnings?

like image 670
Daniel Bonetti Avatar asked Mar 02 '13 13:03

Daniel Bonetti


2 Answers

Look carefully at the warning messages you're actually getting:

1> warning C4514: 'hypot' : unreferenced inline function has been removed

If you are saying to yourself "so?!", then that's exactly my point.

Warning C4514 is a notoriously useless one and is literally just crying out to be suppressed globally. It is a completely non-actionable item and describes an expected case when you're working with a library.

Warning C4711—a function has been selected for inline expansion—is another noisy warning you'll see. Of course, you'll only get this one when compiling with optimizations enabled, which is probably why you haven't seen it yet.

Like the linked documentation says, these are "informational warnings" and they're disabled by default. Which is great, except that I, like you, prefer to compile my code with "All Warnings" (/Wall) enabled, and these just add noise. So I turn them back off individually.

You can disable these warnings either by adding the suppressions to your project's properties in the VS IDE, or you can use pragma directives at the top of your code file (e.g., in your precompiled header):

#pragma warning(disable: 4514 4711)
like image 183
Cody Gray Avatar answered Oct 21 '22 00:10

Cody Gray


Maybe this will do the trick:

// you can replace 3 with even lower warning level if needed 
#pragma warning(push, 3) 

#include <Windows.h>
#include <crtdbg.h>
#include "math.h"
//include all the headers who's warnings you do not want to see here

#pragma warning(pop)

If you plan to port your code to a non MS environment then you may wish to wrap all used external headers in a specific header so that it can be changed when porting.

like image 38
blessio Avatar answered Oct 21 '22 02:10

blessio