Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why disable specific warning not working in Visual Studio

With Visual Studio C++ 2013, I have a lot of warning C4100: unreferenced formal parameter, and I want to disable that. I added 4100 to the "Disable Specific Warnings" in the project for both Debug|Release configurations but unfortunately VS still output the warnings.

I was using VS2008, and the Disable Specific Warning was working but now with VS2013, it doesn't. What I'm doing wrong?

EDIT:

Compiler command line :

/GS /analyze- /W3 /wd"4100" /Zc:wchar_t /I [...] /Zi /Gm- /Od /Fd".\" /fp:precise /D "_WIN32_WINNT=0x0601" /D "_CRT_SECURE_NO_WARNINGS" /D [...] /errorReport:prompt /WX- /Zc:forScope /GR /Gd /Oy- /MDd /Fa"debug\" /EHsc /nologo /Fo"debug\" /Fp"debug\project1.pch"

Additionnal options:

-Zm200 -w34100 -w34189 /MP
like image 887
Vincent Avatar asked Dec 05 '13 14:12

Vincent


People also ask

How do I disable a specific warning in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

How do I turn off error warnings?

Description. We currently have only two ways to disable compiler warnings-as-errors: either make none of them errors using --disable-warnings-as-errors or disable all errors with a compiler flag. There is no way to disable specific warnings-as-errors from the SCons command line due to the order of the compiler flags.

How do I ignore warnings in C#?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.


2 Answers

In retrospect, it seems obvious, but I had to re-read the original ? and user1661176's answer carefully and do some research to realize I had to use both of the following in my ".pro" file to make this work:

QMAKE_CXXFLAGS_WARN_ON -= -w34100
QMAKE_CXXFLAGS += -wd4100

This answer is given just so someone else finding this ? can get the answer quickly without needing to do additional research.

The reason to do this, to me, seems obvious. I like to leave the parameter names in functions created by choosing "Go to slot" in Qt Creator, so that I can have a hint at what the parameters do just by looking at them, even if I don't use them; just in case I decide to use them later. I'm also not keen on e.g. wrapping parameter names in e.g. const QDate* UNUSED(date) which impedes readability by making functions look cluttered.

If you follow this route of suppressing these warnings too, I suggest you turn them back on from time to time and check these warnings, just in case you can remove some unneeded parameters in your own functions, or can use parameters you aren't using, but should be, from your function declarations/implementations.

(That this is for Qt seems indicated, by the OP's specification of the qmake tag.)

Edit: With the most recent Qt Creator version, 4.7.1, one gets a whole slew of warnings, including unused parameters. One that is inarguably unsuitable for Qt is "code will never be executed," in cases where a qDebug() << "some text; occurs in release mode; and it also flags most(?) implicit conversions. There is no way to disable individual warning types for it. However, you can disable all of them by going to the little toolbar to the right of the title of the "Issues" pane. The one on the extreme right is a funnel. Click on it, and you can disable the Clang warnings, by unchecking "Clang Code Model". Don't get me wrong - these warnings can point out important issues; so I enable them to look through them, but most of mine were pretty trivial, IMHO (e.g. having to do with not rewriting my code to use new language features). Once I've addressed issues I think are important, I disable them again.

I also noticed that the above lines don't do the job any more. However, the following do:

QMAKE_CXXFLAGS_WARN_ON -= -w34100
QMAKE_CXXFLAGS_WARN_OFF += -wd4100

You may or may not need to make this change in Visual Studio with the latest version of Qt, as well.

like image 95
CodeLurker Avatar answered Oct 21 '22 11:10

CodeLurker


This was driving me nuts for a while now. My problem was that Qt's default qmake.conf for win32-msvc2013 (look under qtdir\mkspecs) contains the following line: QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON -w34100 -w34189

You didn't say you were using Qt, but the -w34100 parameter sets warning 4100 to be seen at the W3 level instead of the W4 level. This will have precedence over the -wd4100, hence you'll still see the warnings. For those of us using qt you can either add QMAKE_CXXFLAGS_WARN_ON -= -w34100 to your .pro file or remove the argument in the mkspecs folder.

like image 20
user1661176 Avatar answered Oct 21 '22 13:10

user1661176