This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Update newlib so that it passes libc++'s tests
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: JF Bastien <jfb at chromium dot org>
- Cc: <newlib at sourceware dot org>
- Date: Tue, 17 Dec 2013 02:04:22 +0000
- Subject: Re: [PATCH] Update newlib so that it passes libc++'s tests
- Authentication-results: sourceware.org; auth=none
- References: <CABdywOcnSpU=r5NGDDzhea4gxALh8LRL4A9vRY31wFjLhtF5zA at mail dot gmail dot com>
On Mon, 16 Dec 2013, JF Bastien wrote:
> - stdint.h: define WCHAR_MIN and WCHAR_MAX according to
> __WCHAR_UNSIGNED__ if it is provided, and correct the limit when
> unsigned (to 32 all-1 bits, not 31). Make sure stdint.h and wchar.h
> are in sync.
A value of 0 as WCHAR_MIN in the unsigned case has the wrong type if
wchar_t promotes to unsigned int / unsigned long (as opposed to, say, if
it's unsigned short promoting to signed int). glibc (2.18 and later) uses
(L'\0' + 0) (if __WCHAR_MIN__ isn't predefined) in the unsigned case to
get the correct promoted version of wchar_t, and similar constructs
involving + L'\0' for WCHAR_MAX to get the right type in those cases as
well.
In general, you need to make sure these constants have the right type,
being the promoted version of the type to which the macros refer,
including int/long differences even when those have the same
representation and alignment - and, for C++, distinguishing the distinct
wchar_t type from the type to which it promotes (the latter being the
right type for such constants) - not just the right value. In #if
expressions they need the same value and signedness as in normal C/C++
code (this means that (L'\0' - 1) is not a correct expression for
WCHAR_MAX in the unsigned case because in #if expressions it would
evaluate to UINTMAX_MAX).
--
Joseph S. Myers
joseph@codesourcery.com