]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
uchar-h: Fix compilation error of <cuchar> in C++ mode on macOS 15.
authorBruno Haible <bruno@clisp.org>
Mon, 1 Sep 2025 22:12:43 +0000 (00:12 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 1 Sep 2025 22:19:09 +0000 (00:19 +0200)
* lib/uchar.in.h: In C++ mode, use CXX_HAVE_UCHAR_H instead of
HAVE_UCHAR_H.
* m4/uchar_h.m4 (gl_UCHAR_H): Set CXX_HAVE_UCHAR_H.
* modules/uchar-h (Makefile.am): Substitute CXX_HAVE_UCHAR_H.

ChangeLog
lib/uchar.in.h
m4/uchar_h.m4
modules/uchar-h

index 67fb38e4573225a14dc529c7bb145d00dc64a1cc..f6f365a118d5cf1f72b309afcaf4293e939a2229 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-09-01  Bruno Haible  <bruno@clisp.org>
+
+       uchar-h: Fix compilation error of <cuchar> in C++ mode on macOS 15.
+       * lib/uchar.in.h: In C++ mode, use CXX_HAVE_UCHAR_H instead of
+       HAVE_UCHAR_H.
+       * m4/uchar_h.m4 (gl_UCHAR_H): Set CXX_HAVE_UCHAR_H.
+       * modules/uchar-h (Makefile.am): Substitute CXX_HAVE_UCHAR_H.
+
 2025-09-01  Collin Funk  <collin.funk1@gmail.com>
 
        sys_types-h tests: Fix a static_assert failure on glibc/alpha.
index a0f43c18ab53fbca1e4f130732cf35f385b26aaf..9a65ac3774134e063b0b27acaaf33c3ff7384079 100644 (file)
@@ -28,7 +28,7 @@
 @PRAGMA_COLUMNS@
 
 /* The include_next requires a split double-inclusion guard.  */
-#if @HAVE_UCHAR_H@
+#if (defined __cplusplus ? @CXX_HAVE_UCHAR_H@ : @HAVE_UCHAR_H@)
 # if defined __HAIKU__
 /* Work around <https://dev.haiku-os.org/ticket/17040>.  */
 #  include <stdint.h>
@@ -83,7 +83,7 @@
 _GL_INLINE_HEADER_BEGIN
 
 
-#if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_CHAR8_TYPE@))
+#if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_CHAR8_TYPE@ : @HAVE_UCHAR_H@)
 
 /* An 8-bit variant of wchar_t.
    Note: This type is only mandated by ISO C 23 or newer, and it does
@@ -97,7 +97,7 @@ typedef unsigned char gl_char8_t;
 
 #endif
 
-#if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
+#if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_UCHAR_TYPES@ : @HAVE_UCHAR_H@)
 
 /* A 16-bit variant of wchar_t.
    Note: This type is only mandated by ISO C 11 or newer.  In ISO C 23
@@ -112,7 +112,7 @@ typedef uint_least16_t gl_char16_t;
 
 #endif
 
-#if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
+#if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_UCHAR_TYPES@ : @HAVE_UCHAR_H@)
 
 /* A 32-bit variant of wchar_t.
    Note: This type is only mandated by ISO C 11 or newer.  In ISO C 23
index 358a0971118d37e0e52253d62912028df5fe3874..b2309385eb802d8040c16fa0d32387b676c521a0 100644 (file)
@@ -1,5 +1,5 @@
 # uchar_h.m4
-# serial 31
+# serial 32
 dnl Copyright (C) 2019-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -21,6 +21,34 @@ AC_DEFUN_ONCE([gl_UCHAR_H],
   fi
   AC_SUBST([HAVE_UCHAR_H])
 
+  dnl On macOS 15, in C mode, <uchar.h> does not exist. But in C++ mode,
+  dnl it exists, and we need to #include_next it, otherwise we get an error
+  dnl "<cuchar> tried including <uchar.h> but didn't find libc++'s <uchar.h>
+  dnl  header."
+  m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])])
+  CXX_HAVE_UCHAR_H=0
+  if test "$CXX" != no; then
+    AC_CACHE_CHECK([whether the C++ compiler has <uchar.h>],
+      [gl_cv_cxx_have_uchar_h],
+      [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
+       dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
+       cat > conftest.cpp <<\EOF
+#include <uchar.h>
+EOF
+       gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
+       if AC_TRY_EVAL([gl_command]); then
+         gl_cv_cxx_have_uchar_h=yes
+       else
+         gl_cv_cxx_have_uchar_h=no
+       fi
+       rm -fr conftest*
+      ])
+    if test $gl_cv_cxx_have_uchar_h = yes; then
+      CXX_HAVE_UCHAR_H=1
+    fi
+  fi
+  AC_SUBST([CXX_HAVE_UCHAR_H])
+
   gl_TYPE_CHAR8_T
   gl_TYPE_CHAR16_T
   gl_TYPE_CHAR32_T
@@ -60,7 +88,7 @@ EOF
   CXX_HAS_CHAR8_TYPE=0
   if test $HAVE_UCHAR_H = 0; then
     if test "$CXX" != no; then
-      AC_CACHE_CHECK([whether the C++ compiler predefines the char8_t types],
+      AC_CACHE_CHECK([whether the C++ compiler predefines the char8_t type],
         [gl_cv_cxx_has_char8_type],
         [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
          dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
index 70998d5d75e77853a19de10729a38bf3c15917ca..636085985758aa82574a08dce209b4f0e0e3a532 100644 (file)
@@ -31,6 +31,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
        $(gl_V_at)$(SED_HEADER_STDOUT) \
              -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
              -e 's/@''HAVE_UCHAR_H''@/$(HAVE_UCHAR_H)/g' \
+             -e 's/@''CXX_HAVE_UCHAR_H''@/$(CXX_HAVE_UCHAR_H)/g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \