]> Savannah Git Hosting - gnulib.git/commitdiff
uchar: Fix compilation errors in C++ mode on OpenBSD.
authorBruno Haible <bruno@clisp.org>
Wed, 19 Aug 2020 18:40:20 +0000 (20:40 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 19 Aug 2020 18:40:20 +0000 (20:40 +0200)
* lib/uchar.in.h (char16_t, char32_t): Don't define in C++ mode if
CXX_HAS_UCHAR_TYPES is 1.
* m4/uchar.m4 (gl_UCHAR_H): Determine whether the C++ compiler
predefines char16_t and char32_t. Substitute CXX_HAS_UCHAR_TYPES.
* modules/uchar (Makefile.am): Substitute CXX_HAS_UCHAR_TYPES.

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

index 0b864f6a0713c64d693bc2c68cf2dbcca7f8026d..bc534bb9a21c8ed154a0e3fbf1110c66f62585af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-08-19  Bruno Haible  <bruno@clisp.org>
+
+       uchar: Fix compilation errors in C++ mode on OpenBSD.
+       * lib/uchar.in.h (char16_t, char32_t): Don't define in C++ mode if
+       CXX_HAS_UCHAR_TYPES is 1.
+       * m4/uchar.m4 (gl_UCHAR_H): Determine whether the C++ compiler
+       predefines char16_t and char32_t. Substitute CXX_HAS_UCHAR_TYPES.
+       * modules/uchar (Makefile.am): Substitute CXX_HAS_UCHAR_TYPES.
+
 2020-08-19  Bruno Haible  <bruno@clisp.org>
 
        Fix compilation errors in C++ mode on OpenBSD.
index b77116d58509e4bd5c895b39ebbf977e4cfdcebd..12f9935cb7cc16dec46556d0ed9e0855764eddff 100644 (file)
@@ -40,7 +40,7 @@
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
 
-#if !@HAVE_UCHAR_H@
+#if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
 
 /* A 16-bit variant of wchar_t.
    Note: This type does *NOT* denote UTF-16 units.  (Only on platforms
@@ -54,7 +54,7 @@ typedef uint_least16_t gl_char16_t;
 
 #endif
 
-#if !@HAVE_UCHAR_H@
+#if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
 
 /* A 32-bit variant of wchar_t.
    Note: This type does *NOT* denote UTF-32 code points.  (Only on platforms
index 0875caa36ddc909fa90fbf3e11b9ed968b5e880c..a573f5da1f16aa6316aecd67cf1ba6bfb064bd4c 100644 (file)
@@ -1,4 +1,4 @@
-# uchar.m4 serial 14
+# uchar.m4 serial 15
 dnl Copyright (C) 2019-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,6 +22,31 @@ AC_DEFUN_ONCE([gl_UCHAR_H],
   gl_TYPE_CHAR16_T
   gl_TYPE_CHAR32_T
 
+  dnl In C++ mode, clang defines 'char16_t' and 'char32_t' as built-in types
+  dnl on some platforms (e.g. OpenBSD 6.7).
+  CXX_HAS_UCHAR_TYPES=0
+  if test $HAVE_UCHAR_H = 0; then
+    if test "$CXX" != no; then
+      AC_CACHE_CHECK([whether the C++ compiler predefines the <uchar.h> types],
+        [gl_cv_cxx_has_uchar_types],
+        [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>.
+         echo 'char16_t a; char32_t b;' > conftest.cpp
+         gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
+         if AC_TRY_EVAL([gl_command]); then
+           gl_cv_cxx_has_uchar_types=yes
+         else
+           gl_cv_cxx_has_uchar_types=no
+         fi
+         rm -fr conftest*
+        ])
+      if test $gl_cv_cxx_has_uchar_types = yes; then
+        CXX_HAS_UCHAR_TYPES=1
+      fi
+    fi
+  fi
+  AC_SUBST([CXX_HAS_UCHAR_TYPES])
+
   dnl Test whether a 'char32_t' can hold more characters than a 'wchar_t'.
   gl_STDINT_BITSIZEOF([wchar_t], [gl_STDINT_INCLUDES])
   if test $BITSIZEOF_WCHAR_T -lt 32; then
index 7215b3674b140123a72d4b9c19a0bf24cb861688..7cddcad2e7d9f64041541149168a865741df2162 100644 (file)
@@ -27,6 +27,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H)
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_UCHAR_H''@|$(NEXT_UCHAR_H)|g' \
+             -e 's|@''CXX_HAS_UCHAR_TYPES''@|$(CXX_HAS_UCHAR_TYPES)|g' \
              -e 's|@''SMALL_WCHAR_T''@|$(SMALL_WCHAR_T)|g' \
              -e 's|@''GNULIB_OVERRIDES_CHAR16_T''@|$(GNULIB_OVERRIDES_CHAR16_T)|g' \
              -e 's|@''GNULIB_OVERRIDES_CHAR32_T''@|$(GNULIB_OVERRIDES_CHAR32_T)|g' \