This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Define char16_t, char32_t consistently with uint_least16_t, uint_least32_t (bug 17979)
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Wed, 7 Feb 2018 16:46:10 -0200
- Subject: Re: Define char16_t, char32_t consistently with uint_least16_t, uint_least32_t (bug 17979)
- Authentication-results: sourceware.org; auth=none
- References: <alpine.DEB.2.20.1802012036000.13065@digraph.polyomino.org.uk>
On 01/02/2018 18:36, Joseph Myers wrote:
> As noted in bug 17979 (and as I noted earlier in
> <https://sourceware.org/ml/libc-alpha/2012-02/msg00647.html>), uchar.h
> has gratuitously complicated code to determine the types for char16_t
> and char32_t, and to reject including that header for pre-C11
> compilers not defining __CHAR16_TYPE__ and __CHAR32_TYPE__. Since
> those types are always required to match uint_least16_t and
> uint_least32_t, which glibc knows how to define without reference to
> such predefined macros, it's safe just to define those types the same
> as the *least* types are defined in stdint.h, so allowing the header
> to work with (for example) GCC 4.3.
>
> This patch implements that. bits/types.h is made to define
> __int_leastN_t and __uint_leastN_t so the logic for those types can
> stay in a single place, and stdint.h is made to use those __*_t to
> define the public *_t types. uchar.h is then made to use
> __uint_least16_t and __uint_least32_t to define char16_t and char32_t,
> so simplifying the logic there. A new test is added that verifies the
> types chosen for char16_t and char32_t do indeed match the types the
> compiler uses for u"" and U"" string literals.
>
> Tested for x86_64. (I have not tested with any of the older compilers
> for which this would actually make a difference to whether you can
> include uchar.h.)
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> +
> +#include <uchar.h>
> +
> +const char16_t *s16 = u"";
> +const char32_t *s32 = U"";
> +
> +static int
> +do_test (void)
> +{
> + /* This is a compilation test. */
> + return 0;
> +}
> +
> +#include <support/test-driver.c>
Maybe we could add these kind of tests on build time to catch on cross-compilation,
as:
#define is_compatible(x, T) _Generic((x), T:1, default: 0)
#define check_compatibility(x, t) \
_Static_assert (is_compatible (x, t), "type not compatible")
check_compatibility (u"", char16_t *);
check_compatibility (U"", char32_t *);