]> Savannah Git Hosting - gnulib.git/commitdiff
c-nullptr: Fix conflict with libstdc++ in GCC >= 11.
authorBruno Haible <bruno@clisp.org>
Mon, 6 Feb 2023 03:15:15 +0000 (04:15 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 6 Feb 2023 03:17:33 +0000 (04:17 +0100)
Reported by Bjarni Ingi Gislason <bjarniig@simnet.is> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00030.html>.

* 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.

ChangeLog
m4/c-nullptr.m4

index 4c9bff951b61c0a9dc18517d275bf697b8c1b5ee..7a2c0cfa2fa1030b5799e543a36de11f05d52a5c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-02-05  Bruno Haible  <bruno@clisp.org>
+
+       c-nullptr: Fix conflict with libstdc++ in GCC >= 11.
+       Reported by Bjarni Ingi Gislason <bjarniig@simnet.is> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00030.html>.
+       * 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  <bruno@clisp.org>
 
        c-nullptr: Add tests.
index af7985469689b147be6eb70cdb92ce62de80dafc..960eeff18dcf27ed2e7641786316e18db25eddf9 100644 (file)
@@ -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])
 ])