From a8959ecf817c5def4d063c6ecbdaa89688c3981e Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 16 Jul 2020 21:56:17 +0200 Subject: [PATCH] C++20: work around g++ 10.1 bug #95242 With GCC 10.1 all comparisons that default to the <=> C++20 comparison operator emit a spurious zero-as-null-pointer-constant warning, which is an error in our configuration. This is due to an implementation choice in the libstdc++ library, so it also causes warning from clang++ 10.0 when using the same libstdc++ library. A fix for GCC PR95242 was committed in g++ (not in libstdc++), so while g++ 10.2 might be fixed, clang++ will need a similar fix. I've seen those failures on Arch linux with gcc 10.1.0-2 and clang 10.0.0-3. On Debian sid, g++ 10.1.0-4 seems to already include the fix. * m4/gccwarn.m4: Include a string comparison in the test code so that -Wzero-as-null-pointer-constant is not enabled if it would produce warnings on such statements. --- m4/gccwarn.m4 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/m4/gccwarn.m4 b/m4/gccwarn.m4 index e5b316923..4f719e55f 100644 --- a/m4/gccwarn.m4 +++ b/m4/gccwarn.m4 @@ -20,7 +20,21 @@ AC_DEFUN([CF_GXX_WARNINGS], [ cat > conftest.$ac_ext < +int main(int argc, char *argv[[]]) +{ + // This string comparison is here to detect superfluous + // zero-as-null-pointer-constant errors introduced with GCC 10.1's + // libstdc++, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242 + // This is fixed in g++ 10.2, but has the fix is in the compiler + // instead of the library, clang++ 10.0 also has trouble with it. + // If we hit a compiler with this issue, we simply do not use + // -Wzero-as-null-pointer-constant. + std::string a{"foo"}, b{"bar"}; + if (b < a) + return 1; + return argv[[argc-1]] == nullptr; +} EOF cf_save_CXXFLAGS="$CXXFLAGS" ac_cv_prog_gxx_warn_flags="-W -Wall"