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?

i hate warningsaserrors, warnings are warnings, errors are errors.
i understand epic might want to do that with their own code.
but i don’t like it being forced on people.
though i’m not sure if it’s epic or the compiler the one that enable this. since the errors i get on windows and linux are different. (which makes it even more annoying).
i know it’s a compiler flag so someone had to put it.

there are times where you are fine with certain warnings. and sometimes a plugin might generate a warning.
or some warnings might be fake, or useless.
and another thing that happens on all the teams i’ve worked with, is that people stops paying attention to the warnings, since if they assume that any important warning will break the build.
all these things makes it apparent to me that “warnings as errors” is not an ideal long term strategy.
when i have a warning that are so severe that it needs to behave as an error, then it’s not a warning, it’s an error. and i mark it as such.

i want to find where to disable it.

i’ve found a few variables in Project.Target.cs
like
DefaultWarningLevel = WarningLevel.Warning;
bWarningsAsErrors = false;

i haven’t verified they work yet.

1 Like

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.

Surpressing warnings is not the best way, but getting compile errors for warnings is not acceptable in some cases. Really no need to discuss that.

1 Like