Fix newlib/testsuite/newlib.wctype/twctype.c compilation for targets with a 16-bit wint_t.

Message ID 20260713004128.744560-1-jdx@o2.pl
State New
Headers
Series Fix newlib/testsuite/newlib.wctype/twctype.c compilation for targets with a 16-bit wint_t. |

Commit Message

Jan Dubiec July 13, 2026, 12:40 a.m. UTC
  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. The
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/twctype.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 <jdx@o2.pl>
---
 newlib/testsuite/newlib.wctype/twctype.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Jeff Johnston July 15, 2026, 12:08 a.m. UTC | #1
Patch merged.

-- Jeff J.

On Sun, Jul 12, 2026 at 8:42 PM Jan Dubiec <jdx@o2.pl> 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. The
> 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/twctype.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 <jdx@o2.pl>
> ---
>  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
>
>
  

Patch

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'));