bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] nullptr: work around GCC 14 nullptr sentinel bug


From: Paul Eggert
Subject: [PATCH 2/2] nullptr: work around GCC 14 nullptr sentinel bug
Date: Sat, 27 Apr 2024 10:38:05 -0700

* m4/nullptr.m4 (gl_NULLPTR): Work around GCC bug 114780.
---
 ChangeLog       |  3 +++
 doc/gnulib.texi |  4 ++++
 m4/nullptr.m4   | 18 ++++++++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b30238f934..e341b62968 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2024-04-27  Paul Eggert  <eggert@cs.ucla.edu>
 
+       nullptr: work around GCC 14 nullptr sentinel bug
+       * m4/nullptr.m4 (gl_NULLPTR): Work around GCC bug 114780.
+
        stddef: work around GCC 14 stddef.h bugs
        * lib/stddef.in.h: Do nothing if _@GUARD_PREFIX@_STDDEF_H is
        defined, as stddef.h has already been included.  This works
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index ac8c01d1e1..aa0eb57f62 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -978,6 +978,10 @@ Portability problems fixed by Gnulib:
 Some platforms lack @code{nullptr}:
 For C: GCC 12, Clang 15, and other pre-2023 C compilers.
 For C++: pre-2011 C++ compilers.
+
+@item
+Some platforms incorrectly warn when @code{nullptr} is a sentinel argument:
+GCC 13.2 and 14.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/nullptr.m4 b/m4/nullptr.m4
index eeeee99495..4f2284296a 100644
--- a/m4/nullptr.m4
+++ b/m4/nullptr.m4
@@ -1,5 +1,5 @@
 # nullptr.m4
-# serial 1
+# serial 2
 dnl Copyright 2023-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -14,7 +14,21 @@ AC_DEFUN([gl_NULLPTR],
      AC_CACHE_CHECK([for C nullptr], [gl_cv_c_nullptr],
        [AC_COMPILE_IFELSE(
           [AC_LANG_SOURCE([[int *p = nullptr;]])],
-          [gl_cv_c_nullptr=yes],
+          [gl_cv_c_nullptr=yes
+           # Work around <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114780>.
+           gl_saved_CFLAGS=$CFLAGS
+           CFLAGS="$CFLAGS -Wall -Werror"
+           AC_COMPILE_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[void f (char const *, ...) __attribute__ ((sentinel));]],
+                [[f ("", nullptr);]])],
+             [],
+             [AC_COMPILE_IFELSE(
+                [AC_LANG_PROGRAM(
+                   [[void f (char const *, ...) __attribute__ ((sentinel));]],
+                   [[f ("", (void *) 0);]])],
+                [gl_cv_c_nullptr='not as a sentinel'])])
+           CFLAGS=$gl_saved_CFLAGS],
           [gl_cv_c_nullptr=no])])
       gl_c_nullptr=$gl_cv_c_nullptr
       AC_LANG_POP([C])],
-- 
2.44.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]