+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.
/* 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
#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
-# 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,
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
-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' \