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

Replaced 0 with PUGIXML_NULL when a nullptr would have been needed. #586

Merged
merged 7 commits into from
Oct 20, 2023

Conversation

PhilipBotha
Copy link

Fixed a GCC warning about using a const literal zero in place of nullptr (-Wzero-as-null-pointer-constant) by using the already defined PUGIXML_NULL macro when the C++ version supports nullptr.

Added the suffix UZ to size_t.

Added fixed GCC warning about using const literal zero in place of nullptr (-Wzero-as-null-pointer-constant).
src/pugixml.cpp Outdated Show resolved Hide resolved
src/pugixml.cpp Outdated Show resolved Hide resolved
@zeux
Copy link
Owner

zeux commented Oct 13, 2023

Just want to check - does using NULL instead of PUGIXML_NULL in pugixml.cpp also silence the warnings?

The reason to prefer NULL in this case is that since pugixml isn't a C++11 codebase, and 0 vs nullptr have different semantics in certain cases for overloads, it would be a little safer for future changes to use NULL internally. We use PUGIXML_NULL in the external interface to ensure maximum compliance vs aggressive analysis tools like clang-tidy but I'm wondering if this is necessary in the implementation.

@zeux
Copy link
Owner

zeux commented Oct 13, 2023

If this PR switches to NULL + has no unrelated whitespace changes I'd be happy to merge this.

@PhilipBotha
Copy link
Author

Using NULL does fix the issue with GCC but Clang still complains :

warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]

So to keep it compatible with C++ from before C++11, PUGIXML_NULL is the better solution.

Removed white space that was changed.
@zeux
Copy link
Owner

zeux commented Oct 14, 2023

Using NULL does fix the issue with GCC but Clang still complains

That is unfortunate :-/ gcc explicitly silences this for NULL, https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=752e7593b0f19af233a0b7e72daab8413662b605, but it looks like clang version was implemented before this change was in effect, and never relaxed.

NULL felt like a straightforward fix but PUGIXML_NULL is significantly noisier, and we can't use nullptr because pre-C++11 support is important :-/ I'm now considering possibly silencing this diagnostic for clang in the source file via pragmas.

@zeux
Copy link
Owner

zeux commented Oct 20, 2023

I'm going to merge this as is for now; we'll see if clang revisits the gcc compatibility (in which case we could enable the warning on clang depending on the version), but this definitely provides the readability improvements that the warning was intended to carry without sacrificing anything.

@zeux zeux merged commit 1ade1d4 into zeux:master Oct 20, 2023
22 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants