From: Bruno Haible Date: Mon, 6 Feb 2023 03:15:15 +0000 (+0100) Subject: c-nullptr: Fix conflict with libstdc++ in GCC >= 11. X-Git-Tag: v1.0~1705 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c24b80755ec08abe0976483984fd0ddff3c12ca4;p=gnulib.git c-nullptr: Fix conflict with libstdc++ in GCC >= 11. Reported by Bjarni Ingi Gislason in . * m4/c-nullptr.m4 (gl_C_NULLPTR): Don't define nullptr if it is already defined. In C++ mode, ignore the result of the configure test and don't define it when we know that the C++ compiler already supports it. --- diff --git a/ChangeLog b/ChangeLog index 4c9bff951b..7a2c0cfa2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-02-05 Bruno Haible + + c-nullptr: Fix conflict with libstdc++ in GCC >= 11. + Reported by Bjarni Ingi Gislason in + . + * m4/c-nullptr.m4 (gl_C_NULLPTR): Don't define nullptr if it is already + defined. In C++ mode, ignore the result of the configure test and don't + define it when we know that the C++ compiler already supports it. + 2023-02-05 Bruno Haible c-nullptr: Add tests. diff --git a/m4/c-nullptr.m4 b/m4/c-nullptr.m4 index af79854696..960eeff18d 100644 --- a/m4/c-nullptr.m4 +++ b/m4/c-nullptr.m4 @@ -18,13 +18,25 @@ AC_DEFUN([gl_C_NULLPTR], ]) AH_VERBATIM([nullptr], -[#ifndef HAVE_C_NULLPTR -# ifndef __cplusplus -# define nullptr ((void *) 0) -# elif 3 <= __GNUG__ -# define nullptr __null +[#ifndef nullptr /* keep config.h idempotent */ +# ifdef __cplusplus +/* For the C++ compiler the result of the configure test is irrelevant. + We know that at least g++ and clang with option -std=c++11 or higher, as well + as MSVC 14 or newer, already have nullptr. */ +# if !(((defined __GNUC__ || defined __clang__) && __cplusplus >= 201103L) \ + || (defined _MSC_VER && 1900 <= _MSC_VER)) +/* Define nullptr as a macro, the best we can. */ +# if 3 <= __GNUG__ +# define nullptr __null +# else +# define nullptr 0L +# endif +# endif # else -# define nullptr 0L +/* For the C compiler, use the result of the configure test. */ +# ifndef HAVE_C_NULLPTR +# define nullptr ((void *) 0) +# endif # endif #endif]) ])