google / google/googletest

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

Open
#3,549 1 comment 1 reaction 1 assignee Claimed by @derekmauro View on GitHub
bug
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.