This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Define char16_t, char32_t consistently with uint_least16_t, uint_least32_t (bug 17979)

On 01/02/2018 18:36, Joseph Myers wrote:
> As noted in bug 17979 (and as I noted earlier in
> <>), 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 <>

> +
> +#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,

#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 *);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]