Why all warnings are treated as errors in the ue4 C++ project, and how to suppress all warnings?

I’m using UE4.23 and Visual Studio 2017. I find that, in the unreal visual studio project, all warnings are treated as errors. And I don’t know how to suppress all warnings.

For example, in a C++ class constructor, a variable is declared and is not used:



AMyActor::AMyActor()
{
  int a; // unused variable
}


and I get this error :


error C4101:  "a" : unreferenced local variable

This makes me confused, because C4101 is a level 3 warning.

Then I try to suppress this warning by using the warning level [FONT=courier new]\W2 :



AMyActor::AMyActor()
{

#pragma warning(push, 2) // set the warning level to 2
    int a;
#pragma warning(pop)

}


but this doesn’t work. BTW, [FONT=courier new]#pragma warning(push, 0) doesn’t work neither.

Then I try to set C4101 to default warning level, and it works:



AMyActor::AMyActor()
{

#pragma warning(push, 2)
#pragma warning(default, 4101) // set C4101 to default warning level
    int a;
#pragma warning(pop)

}


It seems that the warning level of every warning has been changed, why?
I want to suppress all warnings, what should I do? Or how can I set all warnings to their default warning levels?

I have added arguments [FONT=courier new]\W0 and [FONT=courier new]\WX- in the [FONT=courier new]*.response file for [FONT=courier new]cl.exe, it doesn’t work neither.
I have removed the argument [FONT=courier new]-WarningsAsErrors for UBT, it doesn’t work neither.

Why would you want to suppress a warning though? It takes the same amount of time to correct the code as it does to suppress the warning and one day you will get an error and wonder why you never got a warning about it.

The only type of warnings I would suppress is deprecation warnings when I want to use some old code for whatever reason.

If you are using some old poorly written code filled with warnings you might want to spend a day cleaning it up as it probably has some faulty logic as well.

Hello @ , thanks for your reply.

I agree with your opinions about coding writting. I am using a third party C++ library and you can trust that the logic is right, but I still get massive “errors” because all warnings are treated as errors. It’s time-consuming to clean all warnings in a huge C++ library, so is there any solution to suppress all warnings? Can your help me?

And I’m also curious about another problem: In ordinary C++ projects, [FONT=courier new]cl.exe won’t treat warnings as errors. But which arguments cause [FONT=courier new]cl.exe treats warnings as errors in UE C++ projects?