From 976e9476505cd72f6e9a5dbd19dd5b085c2ec4a9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 19 Aug 2020 20:40:20 +0200 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ lib/uchar.in.h | 4 ++-- m4/uchar.m4 | 27 ++++++++++++++++++++++++++- modules/uchar | 1 + 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b864f6a07..bc534bb9a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-08-19 Bruno Haible + + 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 Fix compilation errors in C++ mode on OpenBSD. diff --git a/lib/uchar.in.h b/lib/uchar.in.h index b77116d585..12f9935cb7 100644 --- a/lib/uchar.in.h +++ b/lib/uchar.in.h @@ -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 diff --git a/m4/uchar.m4 b/m4/uchar.m4 index 0875caa36d..a573f5da1f 100644 --- a/m4/uchar.m4 +++ b/m4/uchar.m4 @@ -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 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 . + 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 diff --git a/modules/uchar b/modules/uchar index 7215b3674b..7cddcad2e7 100644 --- a/modules/uchar +++ b/modules/uchar @@ -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' \ -- 2.39.5