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

-Wzero-as-null-pointer-constant hits a few places #1323

Closed
feroldi opened this issue Nov 4, 2017 · 11 comments
Closed

-Wzero-as-null-pointer-constant hits a few places #1323

feroldi opened this issue Nov 4, 2017 · 11 comments

Comments

@feroldi
Copy link

feroldi commented Nov 4, 2017

Compiling with Clang 5.0.0, with libc++ and flag -Wzero-as-null-pointer-constant hits a few usages of NULL:

error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
TEST(SourceManagerTest, calcLineOffsets)
^
/usr/include/gtest/gtest.h:2187:42: note: expanded from macro 'TEST'
# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
                                         ^
/usr/include/gtest/gtest.h:2181:3: note: expanded from macro 'GTEST_TEST'
  GTEST_TEST_(test_case_name, test_name, \
  ^
/usr/include/gtest/internal/gtest-internal.h:1228:38: note: expanded from macro 'GTEST_TEST_'
        #test_case_name, #test_name, NULL, NULL, \
                                     ^
/usr/lib/clang/5.0.0/include/stddef.h:100:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^

I presume it'd be a good choice to change from NULL to nullptr, but I'm not sure about how many other places would need to be changed as well, and whether the change is worth it.

@pavelkryukov
Copy link

There is no nullptr in C++98

@NickeZ
Copy link

NickeZ commented Mar 21, 2018

Is there a temporary fix for this?

@martin-ejdestig
Copy link

I commented in the LLVM bugzilla about this:

https://bugs.llvm.org/show_bug.cgi?id=33771#c5

@barkovv
Copy link
Contributor

barkovv commented Oct 25, 2018

@martin-ejdestig

https://bugs.llvm.org/show_bug.cgi?id=33771#c5

In this discussion it is said that NULL macro is still warned (with "-Wzero-as-null-pointer-constant") since it is integer zero constant.

From the README.md:

  • 1.8.x Release - the 1.8.x is the last release that works with pre-C++11 compilers. The 1.8.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven "critical"

So, if the c++98 support will be dropped in future releases, can we just replace all NULLs with nullptr?

@martin-ejdestig
Copy link

martin-ejdestig commented Oct 26, 2018

@barkovv I do not see your point. I think it's a Clang bug that it warns for this in "system headers" (which is also the title of the linked bug). GCC gets it right.

@gennadiycivil
Copy link
Contributor

@martin-ejdestig

https://bugs.llvm.org/show_bug.cgi?id=33771#c5

In this discussion it is said that NULL macro is still warned (with "-Wzero-as-null-pointer-constant") since it is integer zero constant.

From the README.md:

  • 1.8.x Release - the 1.8.x is the last release that works with pre-C++11 compilers. The 1.8.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven "critical"

So, if the c++98 support will be dropped in future releases, can we just replace all NULLs with nullptr?

C++98 is already dropped in the master
Thanks

@barkovv
Copy link
Contributor

barkovv commented Oct 26, 2018

@martin-ejdestig
I believe that this warning is correct. As far as I know NULL is implementation defined constant that represents a null pointer. Clang's implementation (as many others) sets it to "(void*)0".

@gennadiycivil
I can prepare PR for that.

The NULL -> nullptr migration seems to be simple (for e.g. "$ sed -i 's/NULL/nullptr/g' *.{h, cpp}"). However the manual control is required because "NULL" string can be part of function name or a comment.

@gennadiycivil
Copy link
Contributor

@barkovv thank you very much, yes please prepare the PR. We have done this work in most places with clang-modernize but there are still a few left.

@martin-ejdestig
Copy link

@barkovv The point is that Clang should not warn about code the user does not control (system headers). It skips many other warnings in system headers, as does GCC, but for this particular case Clang warns even in system headers. A bit off topic so I will not respond further.

Anyway, if you fix it directly in googletest, the point is moot.

@Napoleon-BlownApart
Copy link

I've successfully done the replacement as suggested above by @barkovv.
Does the "Merged" indicate mean that the gtest package in Homebrew reflects this change?

@barkovv
Copy link
Contributor

barkovv commented Nov 22, 2018

@Napoleon-BlownApart

"Merged" indicates that this issue is already fixed and the fix will be packaged in the upcoming release for your disto.

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

7 participants