From 6d704d3a1f65cda7c11630cd914b4bc877ddf224 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 20 Aug 2020 01:27:02 +0200
Subject: [PATCH] uchar: Fix compilation errors in C++ mode on macOS.

* m4/uchar.m4 (gl_UCHAR_H): Require gl_ANSI_CXX if present. Include some
system header file before attempting to use 'char16_t' and 'char32_t'.
---
 ChangeLog   |  6 ++++++
 m4/uchar.m4 | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0814926c3c..9262744808 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-19  Bruno Haible  <bruno@clisp.org>
+
+	uchar: Fix compilation errors in C++ mode on macOS.
+	* m4/uchar.m4 (gl_UCHAR_H): Require gl_ANSI_CXX if present. Include some
+	system header file before attempting to use 'char16_t' and 'char32_t'.
+
 2020-08-19  Bruno Haible  <bruno@clisp.org>
 
 	ansi-c++-opt: Work around an autoconf macro reordering problem.
diff --git a/m4/uchar.m4 b/m4/uchar.m4
index a573f5da1f..a17ca1545c 100644
--- a/m4/uchar.m4
+++ b/m4/uchar.m4
@@ -1,4 +1,4 @@
-# uchar.m4 serial 15
+# uchar.m4 serial 16
 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,
@@ -23,7 +23,10 @@ AC_DEFUN_ONCE([gl_UCHAR_H],
   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).
+  dnl on some platforms (e.g. OpenBSD 6.7), and as types defined by many
+  dnl header files (<limits.h>, <stddef.h>, <stdint.h>, <stdio.h>, <stdlib.h>
+  dnl and others) on some platforms (e.g. Mac OS X 10.13).
+  m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])])
   CXX_HAS_UCHAR_TYPES=0
   if test $HAVE_UCHAR_H = 0; then
     if test "$CXX" != no; then
@@ -31,7 +34,11 @@ AC_DEFUN_ONCE([gl_UCHAR_H],
         [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
+         cat > conftest.cpp <<\EOF
+#include <stddef.h>
+char16_t a;
+char32_t b;
+EOF
          gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
          if AC_TRY_EVAL([gl_command]); then
            gl_cv_cxx_has_uchar_types=yes
-- 
2.39.5