googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Gtest macros hide signed/unsigned mismatches in 64 bit builds in MSVC v19 (C4018) which are visible in 32 bit builds

Open bert8128 opened this issue 4 years ago • 1 comments

Describe the bug

Code which would ordinariy raise a MSVC C4018 warning for signed/unsigned mismatch in 32 bit or 64 bit builds are hidden if the comparison is done in a gtest macro (eg ASSERT_GT). I would expect that the compiler would warn in both build modes.

Steps to reproduce the bug

Code to reproduce (compiler flags set to "/W3 /WX"):

#pragma warning(push, 3) // ignore warnings below level 3 coming from third party libraries
#include <gtest/gtest.h>
#pragma warning(pop)

//#pragma warning( 4 : 4018 ) // 'expression': signed/unsigned mismatch
#pragma warning( 3 : 4388 ) // 'expression': signed/unsigned mismatch

struct Sample : public testing::Test
{
};
int ii;
size_t jj;
TEST_F(Sample, test)
{
    ASSERT_GT(ii, jj); // C4018 in 32 bit builds only

    ASSERT_TRUE(ii > jj); // C4018 in 32 bit and 64 bit builds

    auto b = ii > jj; // C4018 in 32 bit and 64 bit builds
    ASSERT_TRUE(b);
}

See it on godbolt: https://godbolt.org/z/d9TzcYT9a

Setting the compiler to x86 generates two warnings.
Setting the compiler to x64 generates only one. The x64 compiler should generate two warnings as well.

This has been observed with MSVC v19, but almost certainly exists with earlier versions. This has been observed with gtest v1.10, but almost certainly exists with earlier versions.

bert8128 avatar Sep 02 '21 09:09 bert8128

It's very vital to fix...

Any updates?

It's also happening with g++

thegreathir avatar Feb 12 '23 12:02 thegreathir