[haiku-bugs] [Haiku] #15990: uchar.h defines the types char16_t, char32_t incorrectly

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Sat, 09 May 2020 01:34:13 -0000

#15990: uchar.h defines the types char16_t, char32_t incorrectly
-----------------------+-----------------------------
 Reporter:  bhaible    |       Owner:  nobody
     Type:  bug        |      Status:  new
 Priority:  normal     |   Milestone:  Unscheduled
Component:  - General  |     Version:  R1/Development
 Keywords:             |  Blocked By:
 Blocking:             |    Platform:  All
-----------------------+-----------------------------
 Seen in hrev54131 (2020-05-04).

 The ISO C 11 standard, section 7.28, specifies that
 - char16_t must be an unsigned type, equivalent to uint_least16_t (defined
 in <stdint.h>),
 - char32_t must be an unsigned type, equivalent to uint_least32_t (defined
 in <stdint.h>).

 The attached test program foo.c verifies this. The expected output is:
 {{{
 char16_t is unsigned? 1
 char32_t is unsigned? 1
 char16_t is as wide as uint_least16_t? 1
 char32_t is as wide as uint_least32_t? 1
 }}}

 On Haiku/x86_64, different bugs are observed in C and C++ mode.

 1) In C mode:
 {{{
 $ gcc foo.c
 $ ./a.out
 char16_t is unsigned? 0
 char32_t is unsigned? 0
 char16_t is as wide as uint_least16_t? 0
 char32_t is as wide as uint_least32_t? 0
 }}}

 2) In C++ mode:
 The file does not even compile, due to type conflicts in the inline
 functions of <uchar.h>.
 {{{
 $ gcc -x c++ foo.c
 In file included from foo.c:1:
 /boot/system/develop/headers/posix/uchar.h: In function 'size_t
 mbrtoc16(char16_t*, const char*, size_t, mbstate_t*)':
 /boot/system/develop/headers/posix/uchar.h:28:17: error: cannot convert
 'char16_t*' to 'wchar_t*'
   return mbrtowc(dest, src, srcLength, mbState);
                  ^~~~
 In file included from /boot/system/develop/headers/posix/uchar.h:8,
                  from foo.c:1:
 /boot/system/develop/headers/posix/wchar.h:66:33: note:   initializing
 argument 1 of 'size_t mbrtowc(wchar_t*, const char*, size_t, mbstate_t*)'
  extern size_t  mbrtowc(wchar_t *dest, const char *src, size_t srcLength,
                         ~~~~~~~~~^~~~
 In file included from foo.c:1:
 /boot/system/develop/headers/posix/uchar.h: In function 'size_t
 mbrtoc32(char32_t*, const char*, size_t, mbstate_t*)':
 /boot/system/develop/headers/posix/uchar.h:39:17: error: invalid
 conversion from 'char32_t*' to 'wchar_t*' [-fpermissive]
   return mbrtowc(dest, src, srcLength, mbState);
                  ^~~~
 In file included from /boot/system/develop/headers/posix/uchar.h:8,
                  from foo.c:1:
 /boot/system/develop/headers/posix/wchar.h:66:33: note:   initializing
 argument 1 of 'size_t mbrtowc(wchar_t*, const char*, size_t, mbstate_t*)'
  extern size_t  mbrtowc(wchar_t *dest, const char *src, size_t srcLength,
                         ~~~~~~~~~^~~~
 }}}
-- 
Ticket URL: <https://dev.haiku-os.org/ticket/15990>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: