Re: [PATCH] Fix newlib/testsuite/newlib.wctype/twctype.c compilation for targets with a 16-bit wint_t.

Jeff Johnston <[email protected]> Tue, 14 Jul 2026 20:08:21 -0400
Newsgroups gmane.comp.lib.newlib
Message-ID <CAOox84sk60cexAUS1ua5nVCm2=h9jaFdi=Q_awL7doPyRAhZgg@mail.gmail.com>
--000000000000d3213f06569b1ffd
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Patch merged.

-- Jeff J.

On Sun, Jul 12, 2026 at 8:42=E2=80=AFPM Jan Dubiec <[email protected]> wrote:

> When the test case is compiled for a target with a 16-bit wint_t, the
> compiler emits the two warnings shown below, causing the test to fail. Th=
e
> code assumes that wint_t is 32 bits wide, which is not always the case.
> This patch fixes the issue.
>
> h8300-elf-gcc  /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c
> -I/mnt/Works/newlib/newlib/testsuite/include -lm -o
> /mnt/Works/xcomp/build-newlib-h8300-linux/h8300-elf/newlib/testsuite/twct=
ype.x
> In file included from
> /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c:7:
> /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c: In function
> 'main':
> /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c:42:23: warning=
:
> unsigned conversion from 'long int' to 'wint_t' {aka 'unsigned int'}
> changes value from '120782' to '55246' [-Woverflow]
>    42 |       CHECK (iswalnum(0x1d7ce));
>       |                       ^~~~~~~
> /mnt/Works/newlib/newlib/testsuite/include/check.h:5:9: note: in
> definition of macro 'CHECK'
>     5 |   if (!(a)) \
>       |         ^
> /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c:43:24: warning=
:
> unsigned conversion from 'long int' to 'wint_t' {aka 'unsigned int'}
> changes value from '120832' to '55296' [-Woverflow]
>    43 |       CHECK (!iswalnum(0x1d800));
>       |                        ^~~~~~~
> /mnt/Works/newlib/newlib/testsuite/include/check.h:5:9: note: in
> definition of macro 'CHECK'
>     5 |   if (!(a)) \
>       |         ^
>
> Signed-off-by: Jan Dubiec <[email protected]>
> ---
>  newlib/testsuite/newlib.wctype/twctype.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/newlib/testsuite/newlib.wctype/twctype.c
> b/newlib/testsuite/newlib.wctype/twctype.c
> index 95be74d63..2275bf44d 100644
> --- a/newlib/testsuite/newlib.wctype/twctype.c
> +++ b/newlib/testsuite/newlib.wctype/twctype.c
> @@ -39,8 +39,13 @@ int main()
>        setlocale (LC_CTYPE, "C-UTF-8");
>        CHECK (iswalpha(0x0967));
>        CHECK (!iswalpha(0x128e));
> +#if __SIZEOF_WINT_T__ > 2
> +      /* These two lines may cause compilation warnings on targets
> +         where wint_t is 16 bits wide, which in turn causes the test
> +         case to fail. */
>        CHECK (iswalnum(0x1d7ce));
>        CHECK (!iswalnum(0x1d800));
> +#endif
>        CHECK (iswcntrl(0x007f));
>        CHECK (!iswcntrl(0x2027));
>        CHECK (iswdigit(L'2'));
> --
> 2.54.0
>
>

--000000000000d3213f06569b1ffd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:verdana,=
sans-serif">Patch merged.</div><div class=3D"gmail_default" style=3D"font-f=
amily:verdana,sans-serif"><br></div><div class=3D"gmail_default" style=3D"f=
ont-family:verdana,sans-serif">-- Jeff J.</div></div><br><div class=3D"gmai=
l_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun=
, Jul 12, 2026 at 8:42=E2=80=AFPM Jan Dubiec &lt;<a href=3D"mailto:[email protected]=
l">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">When the test case is compiled for a target with a 16-bit wint_=
t, the<br>
compiler emits the two warnings shown below, causing the test to fail. The<=
br>
code assumes that wint_t is 32 bits wide, which is not always the case.<br>
This patch fixes the issue.<br>
<br>
h8300-elf-gcc=C2=A0 /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctyp=
e.c -I/mnt/Works/newlib/newlib/testsuite/include -lm -o /mnt/Works/xcomp/bu=
ild-newlib-h8300-linux/h8300-elf/newlib/testsuite/twctype.x<br>
In file included from /mnt/Works/newlib/newlib/testsuite/newlib.wctype/twct=
ype.c:7:<br>
/mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c: In function &#3=
9;main&#39;:<br>
/mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c:42:23: warning: =
unsigned conversion from &#39;long int&#39; to &#39;wint_t&#39; {aka &#39;u=
nsigned int&#39;} changes value from &#39;120782&#39; to &#39;55246&#39; [-=
Woverflow]<br>
=C2=A0 =C2=A042 |=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (iswalnum(0x1d7ce));<br>
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^~~~~~~<br>
/mnt/Works/newlib/newlib/testsuite/include/check.h:5:9: note: in definition=
 of macro &#39;CHECK&#39;<br>
=C2=A0 =C2=A0 5 |=C2=A0 =C2=A0if (!(a)) \<br>
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^<br>
/mnt/Works/newlib/newlib/testsuite/newlib.wctype/twctype.c:43:24: warning: =
unsigned conversion from &#39;long int&#39; to &#39;wint_t&#39; {aka &#39;u=
nsigned int&#39;} changes value from &#39;120832&#39; to &#39;55296&#39; [-=
Woverflow]<br>
=C2=A0 =C2=A043 |=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (!iswalnum(0x1d800));<br>
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^~~~~~~<br>
/mnt/Works/newlib/newlib/testsuite/include/check.h:5:9: note: in definition=
 of macro &#39;CHECK&#39;<br>
=C2=A0 =C2=A0 5 |=C2=A0 =C2=A0if (!(a)) \<br>
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^<br>
<br>
Signed-off-by: Jan Dubiec &lt;<a href=3D"mailto:[email protected]" target=3D"_blank=
">[email protected]</a>&gt;<br>
---<br>
=C2=A0newlib/testsuite/newlib.wctype/twctype.c | 5 +++++<br>
=C2=A01 file changed, 5 insertions(+)<br>
<br>
diff --git a/newlib/testsuite/newlib.wctype/twctype.c b/newlib/testsuite/ne=
wlib.wctype/twctype.c<br>
index 95be74d63..2275bf44d 100644<br>
--- a/newlib/testsuite/newlib.wctype/twctype.c<br>
+++ b/newlib/testsuite/newlib.wctype/twctype.c<br>
@@ -39,8 +39,13 @@ int main()<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0setlocale (LC_CTYPE, &quot;C-UTF-8&quot;);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (iswalpha(0x0967));<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (!iswalpha(0x128e));<br>
+#if __SIZEOF_WINT_T__ &gt; 2<br>
+=C2=A0 =C2=A0 =C2=A0 /* These two lines may cause compilation warnings on =
targets<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0where wint_t is 16 bits wide, which in t=
urn causes the test<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0case to fail. */<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (iswalnum(0x1d7ce));<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (!iswalnum(0x1d800));<br>
+#endif<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (iswcntrl(0x007f));<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (!iswcntrl(0x2027));<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0CHECK (iswdigit(L&#39;2&#39;));<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div>

--000000000000d3213f06569b1ffd--