gtest cause warnings under gcc 4.5.1 #322

Closed
GoogleCodeExporter opened this Issue Jul 28, 2015 · 4 comments

Comments

Projects
None yet
1 participant
Contributor

GoogleCodeExporter commented Jul 28, 2015

Hello, I'm using gtest,

Waning:
Test.cpp.cpp:45770:139: warning: converting ‘false’ to pointer type for 
argument 1 of ‘char 
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’

source line:
EXPECT_EQ(false, bdb->ExistsAttr(NULL, "/xspace/abc/cccc", "abc"));

/// I know it can be rewritten to EXPECT_FALSE(bdb->ExistsAttr(NULL, 
"/xspace/abc/cccc", "abc"));, but it's not the point.

after proprocessing:
switch (0) case 0:
    if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing::internal::IsNullLiteralHelper
(false)) == 1)>::Compare("false", "bdb->ExistsAttr(__null, 
\"/xspace/abc/bbbb\", \"abc\")", false, bdb->ExistsAttr(__null, "/xspace/
abc/bbbb", "abc")))) ;
    else ::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "TestBdb.cpp", 146, gtest_ar.failure_message
()) = ::testing::Message();
}

relatived gtest code:

// Two overloaded helpers for checking at compile time whether an
// expression is a null pointer literal (i.e. NULL or any 0-valued
// compile-time integral constant).  Their return values have
// different sizes, so we can use sizeof() to test which version is
// picked by the compiler.  These helpers have no implementations, as
// we only need their signatures.
//
// Given IsNullLiteralHelper(x), the compiler will pick the first
// version if x can be implicitly converted to Secret*, and pick the
// second version otherwise.  Since Secret is a secret and incomplete
// type, the only expression a user can write that has type Secret* is
// a null pointer literal.  Therefore, we know that x is a null
// pointer literal if and only if the first version is picked by the
// compiler.
char IsNullLiteralHelper(Secret* p);
char (&IsNullLiteralHelper(...))[2];  // NOLINT

Thanks a lot.

Original issue reported on code.google.com by chen3feng on 13 Oct 2010 at 1:57

Contributor

GoogleCodeExporter commented Jul 28, 2015

This is a GCC bug.  gtest isn't trying to actually covert false to a pointer.  
It just uses a Template Meta Programming trick that's blessed by the C++ 
standard to detect NULL literals.

Also, the canonical way to write your assertion is EXPECT_FALSE(...).  That 
will avoid the warning.

Original comment by w...@google.com on 29 Oct 2010 at 4:56

  • Changed state: WontFix
Contributor

GoogleCodeExporter commented Jul 28, 2015

Hi,

And what is the canonical way to rewrite:
EXPECT_EQ(DEBUG_MODE != 0, DLOG_IS_ON(INFO));
?
The problem prevents me compiling Chromium with gcc 4.5.2
TIA

Original comment by dvyu...@google.com on 6 Apr 2011 at 6:42

Contributor

GoogleCodeExporter commented Jul 28, 2015

Please send questions to the mailing list instead of here.  Thanks.

Original comment by w...@google.com on 6 Apr 2011 at 6:47

Contributor

GoogleCodeExporter commented Jul 28, 2015

For the record, there is a really trivial fix (to gtest) for this issue... add 
this additional overload:

char (&IsNullLiteralHelper(bool))[2];

Original comment by matthew....@kitware.com on 12 Feb 2013 at 7:19

gromacs-upload pushed a commit to gromacs/gromacs that referenced this issue Jan 5, 2016

Use EXPECT_TRUE and EXPECT_FALSE in new SIMD tests
gcc 4.7.3 has a bug that means it warns about converting false to a
pointer type (see google/googletest#322), so
we should just use the normal approach in GoogleTest and avoid
problems.

Change-Id: Ic700ded4a645af1e45fc66fde8fffae692ce33ec

@ernestmc ernestmc referenced this issue in ros2/rosidl Feb 5, 2016

Merged

Cpp tests #64

yyang-even pushed a commit to yyang-even/algorithms that referenced this issue Oct 17, 2016

Framework: Silence a GCC warning
Use a integer boolean instead of c++ boolean.
Following warning is silenced:
warning: converting ‘false’ to pointer type for argument 1
of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’

Also see:
google/googletest#322

Change-Id: I152d0b2727f8cae1c798eb14315cedb8ff760250

jfirebaugh added a commit to mapbox/mapbox-gl-native that referenced this issue Jan 11, 2017

@jfirebaugh jfirebaugh referenced this issue in mapbox/mapbox-gl-native Jan 11, 2017

Merged

[tests] Sidestep a gcc or gtest bug #7682

jfirebaugh added a commit to mapbox/mapbox-gl-native that referenced this issue Jan 11, 2017

@ajkr ajkr referenced this issue in facebook/rocksdb Mar 7, 2017

Closed

avoid ASSERT_EQ(false, ...); #1958

facebook-github-bot added a commit to facebook/rocksdb that referenced this issue Mar 9, 2017

avoid ASSERT_EQ(false, ...);
Summary:
lately it fails on travis due to a compiler bug (see google/googletest#322 (comment)). interestingly it seems to affect occurrences of `ASSERT_EQ(false, ...);` but not `ASSERT_EQ(true, ...);`.
Closes #1958

Differential Revision: D4680742

Pulled By: ajkr

fbshipit-source-id: 291fe41

dumganhar pushed a commit to dumganhar/chromium that referenced this issue Mar 14, 2017

Avoid EXPECT_EQ(false, _) in a chromeos unittest.
EXPECT_EQ(false, _) is known to hit a GCC error, EXPECT_FALSE(_) is safer and
direct: google/googletest#322 (comment).

It is causing compilation failure on the unittest inside simplechrome for some
boards. Well, probably nobody expect me may be doing that, but I still think it
is nicer to keep it compiling, as long as it can be done in a simple change.

BUG=none
TEST=`ninja chromeos_unittests` in simplechrome environment.

Review-Url: https://codereview.chromium.org/2748013002
Cr-Commit-Position: refs/heads/master@{#456624}

ligfx added a commit to ligfx/dolphin that referenced this issue Mar 25, 2017

UnitTests: use EXPECT_TRUE/EXPECT_FALSE (fixes warnings)
Using `EXPECT_EQ` with boolean literals can cause a warning in certain
versions of GCC. See google/googletest#322

Fixes warnings:

```
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_Basics_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:15:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_BitGetSet_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringBeginsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:23:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:25:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:26:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringEndsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:35:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:37:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:38:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:39:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
c
```

ligfx added a commit to ligfx/dolphin that referenced this issue Mar 25, 2017

UnitTests: use EXPECT_TRUE/EXPECT_FALSE (fixes warnings)
Using `EXPECT_EQ` with boolean literals can cause a warning in certain
versions of GCC. See google/googletest#322

Fixes warnings:

```
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_Basics_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:15:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_BitGetSet_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringBeginsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:23:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:25:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:26:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringEndsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:35:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:37:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:38:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:39:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
c
```

mahdihijazi pushed a commit to mahdihijazi/dolphin that referenced this issue Apr 27, 2017

UnitTests: use EXPECT_TRUE/EXPECT_FALSE (fixes warnings)
Using `EXPECT_EQ` with boolean literals can cause a warning in certain
versions of GCC. See google/googletest#322

Fixes warnings:

```
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_Basics_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:15:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/BitSetTest.cpp: In member function 'virtual void BitSet_BitGetSet_Test::TestBody()':
../Source/UnitTests/Common/BitSetTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringBeginsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:23:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:25:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:26:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:27:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp: In member function 'virtual void StringUtil_StringEndsWith_Test::TestBody()':
../Source/UnitTests/Common/StringUtilTest.cpp:35:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:37:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:38:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
../Source/UnitTests/Common/StringUtilTest.cpp:39:165: error: converting 'false' to pointer type for argument 1 of 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' [-Werror=conversion-null]
c
```

edwardstock added a commit to edwardstock/toolboxpp that referenced this issue Dec 10, 2017

rip-nsk added a commit to rip-nsk/orc that referenced this issue Dec 12, 2017

asfgit pushed a commit to apache/orc that referenced this issue Dec 13, 2017

ORC-277. Fix compilation on CentOS 6, which was broken by ORC-261.
Fixes #200

Includes:
* include adaptor to avoid using noexcept if it is not available.
* workaround bug in gcc google/googletest#322

Signed-off-by: Owen O'Malley <omalley@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment