0

I have just installed a fresh Visual Studio 16.10.3 and added Google Test to my command console app. Right of the bat, I get the following warnings:

Severity Code Description Project File Line Suppression State
Warning C26812 The enum type 'testing::TestPartResult::Type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\gtest-test-part.h 62
Warning C26495 Variable 'testing::internal::Mutex::critical_section_' is uninitialized. Always initialize a member variable (type.6). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\internal\gtest-port.h 1804
Warning C26495 Variable 'testing::internal::Mutex::critical_section_init_phase_' is uninitialized. Always initialize a member variable (type.6). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\internal\gtest-port.h 1804
Warning C26495 Variable 'testing::internal::Mutex::owner_thread_id_' is uninitialized. Always initialize a member variable (type.6). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\internal\gtest-port.h 1804
Warning C26495 Variable 'testing::internal::Mutex::type_' is uninitialized. Always initialize a member variable (type.6). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\internal\gtest-port.h 1804
Warning C26812 The enum type 'testing::internal::Mutex::StaticConstructorSelector' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). Tests D:\C++\ConsoleTest\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\include\gtest\internal\gtest-port.h 1804

I tried suppressing the warnings by surrounding #include "pch.h" as described here:

#pragma warning(push, 0)  
#include "pch.h"
#pragma warning(pop)

However, that didn't work - instead, I only got an additional warning that

#pragma warning(pop): no matching '#pragma warning(push)' (C4193)

I also read the Broken Warnings Theory. Unfortunately, I have to admit that I do not understand it. I think this is the relevant section:

To suppress the warning in external headers, we need to both specify which headers are external and what the warning level in those headers should be:

cl.exe /experimental:external /external:I some_lib_dir /external:W0 /W4 my_prog.cpp

This would effectively get rid of any warning inside some_hdr.hpp while preserving warnings inside my_prog.cpp.

But where would I add these switches and what would be the correct path variable for googletest?

Thank you in advance for your help!

Markstar
  • 639
  • 9
  • 24

1 Answers1

1

Instead of

suppressing the warnings by surrounding #include "pch.h"

you should use the warning pragma to surround both header files(gtest-port.h and gtest-test-part.h), which can be found in External Dependencies in Solution Explorer of the Visual Studio project. The detailed methods are as below.

  • Add the following code to the very beginning and end of gtest-port.h

    #pragma warning( push )
    #pragma warning( disable : 26495 )
    #pragma warning( disable : 26812 )
    
    // Original Code
    
    #pragma warning( pop )
    
  • Similarly, add the following code to the very beginning and end of gtest-test-part.h

    #pragma warning( push )
    #pragma warning( disable : 26812 )
    
    // Original Code
    
    #pragma warning( pop )
    
Yao
  • 11
  • 2