Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:

    Code:
    AMyActor::AMyActor()
    {
      int a; // unused variable
    }
    and I get this error :
    Code:
    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 \W2 :

    Code:
    AMyActor::AMyActor()
    {
    
    #pragma warning(push, 2) // set the warning level to 2
        int a;
    #pragma warning(pop)
    
    }

    but this doesn't work. BTW, #pragma warning(push, 0) doesn't work neither.



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

    Code:
    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 \W0 and \WX- in the *.response file for cl.exe, it doesn't work neither.
    I have removed the argument -WarningsAsErrors for UBT, it doesn't work neither.

    #2
    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.

    Comment


      #3
      Originally posted by GarnerP57 View Post
      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 GarnerP57 , 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, cl.exe won't treat warnings as errors. But which arguments cause cl.exe treats warnings as errors in UE C++ projects?

      Comment

      Working...
      X