On 2/9/23 11:31, Bruno Haible wrote:
* If we '#define nullptr __null' again after including the header files,
it will be usable with varargs, but will
- violate the requirement that nullptr is an instance of nullptr_t,
- and thus open up problems with overloading again.
I don't know how to proceed here.
Let's treat C++ overloading like we already treat C _Generic, that is,
as a documented limitation of the substitute nullptr macro. This should
be good enough for Gnulib itself. I installed the attached to document
that, and to work around the Apple clang 14 incompatibility with it in mind.
On 2/9/23 12:08, Arsen Arsenović wrote:
It's, to my awareness, not possible to correctly and portably implement
nullptr in-language.
Yes, but all that's needed here is to implement Gnulib's limited
substitute well enough to work with Apple clang 14 and any other
compilers that have similar incompatibilities with current C++. I hope
the attached patch does that, though I'm by no means a C++ whiz.From 36f06b07d9cfb3974c160ecc22def3cb1b117106 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 9 Feb 2023 17:09:23 -0800
Subject: [PATCH] nullptr: work around Apple clang 14 issue
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2023-02/msg00098.html
* doc/gnulib.texi (nullptr): Document limitations better.
* m4/nullptr.m4 (gl_NULLPTR): Check for incompatibility of macOS
clang 14.0.0 (clang-1400.0.29.202), where <stddef.h> defines a
non-working nullptr macro.
---
ChangeLog | 10 ++++++++++
doc/gnulib.texi | 7 ++++---
m4/nullptr.m4 | 30 ++++++++++++++++++++----------
3 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 867107bb14..ce5ce330e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-02-09 Paul Eggert <[email protected]>
+
+ nullptr: work around Apple clang 14 issue
+ Problem reported by Bruno Haible in:
+ https://lists.gnu.org/r/bug-gnulib/2023-02/msg00098.html
+ * doc/gnulib.texi (nullptr): Document limitations better.
+ * m4/nullptr.m4 (gl_NULLPTR): Check for incompatibility of macOS
+ clang 14.0.0 (clang-1400.0.29.202), where <stddef.h> defines a
+ non-working nullptr macro.
+
2023-02-09 Bruno Haible <[email protected]>
math: Fix compilation error in C++ mode on macOS 12.5.
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 6fe2678834..28d8c20d8c 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -954,9 +954,10 @@ In C, it has type @code{void *}; in C++ it has an integer type.
@item
On older platforms Gnulib cannot easily emulate @code{nullptr_t}, so
-null pointer type checking is more error prone, and @code{_Generic}
-expressions cannot reliably distinguish @code{nullptr}'s type from
-integer or @code{void *} types.
+null pointer type checking is more error prone. In C, @code{_Generic}
+expressions cannot reliably distinguish the type of @code{nullptr}
+from integer or @code{void *} types. C++ overloading has similar
+limitations.
@end itemize
@node static_assert
diff --git a/m4/nullptr.m4 b/m4/nullptr.m4
index a0b438be94..1f8ab51b85 100644
--- a/m4/nullptr.m4
+++ b/m4/nullptr.m4
@@ -28,20 +28,30 @@ AC_DEFUN([gl_NULLPTR],
[AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([[int *p = nullptr;]])],
[gl_cv_cxx_nullptr=yes],
- [gl_cv_cxx_nullptr=no])])
- gl_cxx_nullptr=$gl_cv_cxx_nullptr
- AC_LANG_POP([C++])],
- [gl_cxx_nullptr=no])
- if test "$gl_cxx_nullptr" = yes; then
- AC_DEFINE([HAVE_CXX_NULLPTR], [1], [Define to 1 if C++ nullptr works.])
- fi
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE([[#include <stddef.h>
+ int *p = nullptr;]])],
+ [gl_cv_cxx_nullptr="yes, but it is a <stddef.h> macro"],
+ [gl_cv_cxx_nullptr=no])])])
+ AS_CASE([$gl_cv_cxx_nullptr],
+ [yes], [gl_have_cxx_nullptr=1],
+ [yes*], [gl_have_cxx_nullptr="(-1)"],
+ [gl_have_cxx_nullptr=0])
+ AC_DEFINE_UNQUOTED([HAVE_CXX_NULLPTR], [$gl_have_cxx_nullptr],
+ [Define to 1 if C++ nullptr works, 0 if not,
+ (-1) if it is a <stddef.h> macro.])
+ AC_LANG_POP([C++])])
])
- AH_VERBATIM([nullptr],
-[#ifndef nullptr /* keep config.h idempotent */
+ AH_VERBATIM([zznullptr],
+[#if defined __cplusplus && HAVE_CXX_NULLPTR < 0
+# include <stddef.h>
+# undef/**/nullptr
+#endif
+#ifndef nullptr
# if !defined __cplusplus && !defined HAVE_C_NULLPTR
# define nullptr ((void *) 0)
-# elif defined __cplusplus && !defined HAVE_CXX_NULLPTR
+# elif defined __cplusplus && HAVE_CXX_NULLPTR <= 0
# if 3 <= __GNUG__
# define nullptr __null
# else
--
2.39.1