This is the mail archive of the libc-alpha@sourceware.org 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 Wed, 7 Feb 2018, Adhemerval Zanella wrote:

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

The test above is fully functional for cross compilation (provided you 
compile the testsuite, not just glibc itself, of course).

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

This would be problematic because of -Wwrite-strings meaning the types end 
up as const char16_t * and const char32_t *.  The test as written works 
whether or not the type ends up being const-qualified.  (You don't want a 
test that actually relies on -Wwrite-strings being in use to get the 
tested-for type, because it's not ideal that -Wwrite-strings works by 
changing types of string constants; see GCC bug 61579.)

-- 
Joseph S. Myers
joseph@codesourcery.com


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