Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtest cause warnings under gcc 4.5.1 #322

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

gtest cause warnings under gcc 4.5.1 #322

GoogleCodeExporter opened this issue Jul 28, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

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

@GoogleCodeExporter
Copy link
Contributor Author

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

@GoogleCodeExporter
Copy link
Contributor Author

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

@GoogleCodeExporter
Copy link
Contributor Author

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

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

@GoogleCodeExporter
Copy link
Contributor Author

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
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
yyang-even pushed a commit to yyang-even/algorithms that referenced this issue Oct 17, 2016
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
facebook-github-bot pushed a commit to facebook/rocksdb that referenced this issue Mar 9, 2017
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
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
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
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
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/toolbox 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
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>
luebbers added a commit to OFS/opae-sdk that referenced this issue Mar 30, 2018
luebbers added a commit to OFS/opae-sdk that referenced this issue Apr 17, 2018
yappy added a commit to yappy/DollsKit that referenced this issue Dec 25, 2018
gcc のバグ
clang でも起きているのは謎 (同じバグを持っていた?)
google/googletest#322
wooksong added a commit to wooksong/nnstreamer that referenced this issue Sep 18, 2019
A GCC bug [1] might cause warnings related to 'conversion-null' when
using googletest macros with !FALSE as arguments. Therefore, in the case
that Werror is true, the build would be broken by this bug. To avoid
such situation, this patch replaces EXPECT_EQs in the plugin unit tests
with EXPECT_TRUE or EXPECT_FALSE.

[1] google/googletest#322

Signed-off-by: Wook Song <wook16.song@samsung.com>
wooksong added a commit to wooksong/nnstreamer that referenced this issue Sep 19, 2019
A GCC bug [1] might cause warnings related to 'conversion-null' when
using googletest macros with !FALSE as arguments. Therefore, in the case
that Werror is true, the build would be broken by this bug. To avoid
such situation, this patch replaces EXPECT_EQs in the plugin unit tests
with EXPECT_TRUE or EXPECT_FALSE.

[1] google/googletest#322

Signed-off-by: Wook Song <wook16.song@samsung.com>
wooksong added a commit to wooksong/nnstreamer that referenced this issue Sep 19, 2019
A GCC bug [1] might cause warnings related to 'conversion-null' when
using googletest macros with !FALSE as arguments. Therefore, in the case
that Werror is true, the build would be broken by this bug. To avoid
such situation, this patch replaces EXPECT_EQs in the plugin unit tests
with EXPECT_TRUE or EXPECT_FALSE.

[1] google/googletest#322

Signed-off-by: Wook Song <wook16.song@samsung.com>
myungjoo pushed a commit to nnstreamer/nnstreamer that referenced this issue Sep 19, 2019
A GCC bug [1] might cause warnings related to 'conversion-null' when
using googletest macros with !FALSE as arguments. Therefore, in the case
that Werror is true, the build would be broken by this bug. To avoid
such situation, this patch replaces EXPECT_EQs in the plugin unit tests
with EXPECT_TRUE or EXPECT_FALSE.

[1] google/googletest#322

Signed-off-by: Wook Song <wook16.song@samsung.com>
oran-osc-github pushed a commit to o-ran-sc/ric-plt-sdl that referenced this issue Nov 19, 2019
Certain gcc versions will give (per my understanding false positive)
warning when 'EXPECT_EQ' macro is used so that other argument is
'true' or 'false'.

For example, Ubuntu 16.04 has by default such a gcc version.

See some related discussion below:
google/googletest#322

We have defined all compiler warning to be treated as errors, thus
above issue will lead to compilation error.

Simple fix is to use 'EXPECT_TRUE' or 'EXPECT_FALSE' instead. Those are
more readable, and thus better choice anyway.

Signed-off-by: Rolf Badorek <rolf.badorek@nokia.com>
Change-Id: Ib0f3841c1b6fe2cf95eac3e4dc0cbcba9c3c8268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant