immutable: Add tests.
[gnulib.git] / m4 / uchar.m4
blob268d81a233194101f6a3de498b5dd925b29d0c70
1 # uchar.m4 serial 16
2 dnl Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Bruno Haible.
8 dnl Prepare the overridden <uchar.h>.
10 AC_DEFUN_ONCE([gl_UCHAR_H],
12   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
14   gl_CHECK_NEXT_HEADERS([uchar.h])
15   if test $ac_cv_header_uchar_h = yes; then
16     HAVE_UCHAR_H=1
17   else
18     HAVE_UCHAR_H=0
19   fi
20   AC_SUBST([HAVE_UCHAR_H])
22   gl_TYPE_CHAR16_T
23   gl_TYPE_CHAR32_T
25   dnl In C++ mode, clang defines 'char16_t' and 'char32_t' as built-in types
26   dnl on some platforms (e.g. OpenBSD 6.7), and as types defined by many
27   dnl header files (<limits.h>, <stddef.h>, <stdint.h>, <stdio.h>, <stdlib.h>
28   dnl and others) on some platforms (e.g. Mac OS X 10.13).
29   m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])])
30   CXX_HAS_UCHAR_TYPES=0
31   if test $HAVE_UCHAR_H = 0; then
32     if test "$CXX" != no; then
33       AC_CACHE_CHECK([whether the C++ compiler predefines the <uchar.h> types],
34         [gl_cv_cxx_has_uchar_types],
35         [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
36          dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
37          cat > conftest.cpp <<\EOF
38 #include <stddef.h>
39 char16_t a;
40 char32_t b;
41 EOF
42          gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
43          if AC_TRY_EVAL([gl_command]); then
44            gl_cv_cxx_has_uchar_types=yes
45          else
46            gl_cv_cxx_has_uchar_types=no
47          fi
48          rm -fr conftest*
49         ])
50       if test $gl_cv_cxx_has_uchar_types = yes; then
51         CXX_HAS_UCHAR_TYPES=1
52       fi
53     fi
54   fi
55   AC_SUBST([CXX_HAS_UCHAR_TYPES])
57   dnl Test whether a 'char32_t' can hold more characters than a 'wchar_t'.
58   gl_STDINT_BITSIZEOF([wchar_t], [gl_STDINT_INCLUDES])
59   if test $BITSIZEOF_WCHAR_T -lt 32; then
60     SMALL_WCHAR_T=1
61   else
62     SMALL_WCHAR_T=0
63   fi
64   dnl SMALL_WCHAR_T is expected to be 1 on 32-bit AIX, Cygwin, native Windows.
65   AC_SUBST([SMALL_WCHAR_T])
67   dnl Check for declarations of anything we want to poison if the
68   dnl corresponding gnulib module is not in use, and which is not
69   dnl guaranteed by C11.
70   gl_WARN_ON_USE_PREPARE([[#include <uchar.h>
71     ]], [c32rtomb mbrtoc32])
74 dnl On Haiku 2020, char16_t and char32_t are incorrectly defined.
75 dnl See <https://dev.haiku-os.org/ticket/15990>.
76 AC_DEFUN_ONCE([gl_TYPE_CHAR16_T],
78   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
79   dnl Determine whether gnulib's <uchar.h> would, if present, override char16_t.
80   AC_CACHE_CHECK([whether char16_t is correctly defined],
81     [gl_cv_type_char16_t_works],
82     [AC_COMPILE_IFELSE(
83        [AC_LANG_PROGRAM([[
84           #include <uchar.h>
85           /* For simplicity, assume that uint16_least_t is equivalent to
86              'unsigned short'.  */
87           int verify[(char16_t)(-1) >= 0 && sizeof (char16_t) == sizeof (unsigned short) ? 1 : -1];
88           ]])
89        ],
90        [gl_cv_type_char16_t_works=yes],
91        [gl_cv_type_char16_t_works=no])
92     ])
93   if test $gl_cv_type_char16_t_works = no; then
94     GNULIB_OVERRIDES_CHAR16_T=1
95   fi
97 AC_DEFUN_ONCE([gl_TYPE_CHAR32_T],
99   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
100   dnl Determine whether gnulib's <uchar.h> would, if present, override char32_t.
101   AC_CACHE_CHECK([whether char32_t is correctly defined],
102     [gl_cv_type_char32_t_works],
103     [AC_COMPILE_IFELSE(
104        [AC_LANG_PROGRAM([[
105           #include <uchar.h>
106           /* For simplicity, assume that uint32_least_t is equivalent to
107              'unsigned int'.  */
108           int verify[(char32_t)(-1) >= 0 && sizeof (char32_t) == sizeof (unsigned int) ? 1 : -1];
109           ]])
110        ],
111        [gl_cv_type_char32_t_works=yes],
112        [gl_cv_type_char32_t_works=no])
113     ])
114   if test $gl_cv_type_char32_t_works = no; then
115     GNULIB_OVERRIDES_CHAR32_T=1
116   fi
119 AC_DEFUN([gl_UCHAR_MODULE_INDICATOR],
121   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
122   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
123   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
124   dnl Define it also as a C macro, for the benefit of the unit tests.
125   gl_MODULE_INDICATOR_FOR_TESTS([$1])
128 AC_DEFUN([gl_UCHAR_H_DEFAULTS],
130   GNULIB_OVERRIDES_CHAR16_T=0; AC_SUBST([GNULIB_OVERRIDES_CHAR16_T])
131   GNULIB_OVERRIDES_CHAR32_T=0; AC_SUBST([GNULIB_OVERRIDES_CHAR32_T])
132   GNULIB_BTOC32=0;             AC_SUBST([GNULIB_BTOC32])
133   GNULIB_C32ISALNUM=0;         AC_SUBST([GNULIB_C32ISALNUM])
134   GNULIB_C32ISALPHA=0;         AC_SUBST([GNULIB_C32ISALPHA])
135   GNULIB_C32ISBLANK=0;         AC_SUBST([GNULIB_C32ISBLANK])
136   GNULIB_C32ISCNTRL=0;         AC_SUBST([GNULIB_C32ISCNTRL])
137   GNULIB_C32ISDIGIT=0;         AC_SUBST([GNULIB_C32ISDIGIT])
138   GNULIB_C32ISGRAPH=0;         AC_SUBST([GNULIB_C32ISGRAPH])
139   GNULIB_C32ISLOWER=0;         AC_SUBST([GNULIB_C32ISLOWER])
140   GNULIB_C32ISPRINT=0;         AC_SUBST([GNULIB_C32ISPRINT])
141   GNULIB_C32ISPUNCT=0;         AC_SUBST([GNULIB_C32ISPUNCT])
142   GNULIB_C32ISSPACE=0;         AC_SUBST([GNULIB_C32ISSPACE])
143   GNULIB_C32ISUPPER=0;         AC_SUBST([GNULIB_C32ISUPPER])
144   GNULIB_C32ISXDIGIT=0;        AC_SUBST([GNULIB_C32ISXDIGIT])
145   GNULIB_C32RTOMB=0;           AC_SUBST([GNULIB_C32RTOMB])
146   GNULIB_C32SNRTOMBS=0;        AC_SUBST([GNULIB_C32SNRTOMBS])
147   GNULIB_C32SRTOMBS=0;         AC_SUBST([GNULIB_C32SRTOMBS])
148   GNULIB_C32STOMBS=0;          AC_SUBST([GNULIB_C32STOMBS])
149   GNULIB_C32TOB=0;             AC_SUBST([GNULIB_C32TOB])
150   GNULIB_MBRTOC32=0;           AC_SUBST([GNULIB_MBRTOC32])
151   GNULIB_MBSNRTOC32S=0;        AC_SUBST([GNULIB_MBSNRTOC32S])
152   GNULIB_MBSRTOC32S=0;         AC_SUBST([GNULIB_MBSRTOC32S])
153   GNULIB_MBSTOC32S=0;          AC_SUBST([GNULIB_MBSTOC32S])
154   dnl Assume proper GNU behavior unless another module says otherwise.
155   HAVE_C32RTOMB=1;             AC_SUBST([HAVE_C32RTOMB])
156   HAVE_MBRTOC32=1;             AC_SUBST([HAVE_MBRTOC32])
157   REPLACE_C32RTOMB=0;          AC_SUBST([REPLACE_C32RTOMB])
158   REPLACE_MBRTOC32=0;          AC_SUBST([REPLACE_MBRTOC32])