Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15990 closed bug (fixed)

uchar.h defines the types char16_t, char32_t incorrectly

Reported by: bhaible Owned by: nobody
Priority: normal Milestone: R1/beta2
Component: System/POSIX Version: R1/Development
Keywords: Cc: leorize
Blocked By: Blocking:
Platform: All

Description

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,
                        ~~~~~~~~~^~~~

Attachments (3)

foo.c (498 bytes ) - added by bhaible 4 years ago.
test program
foo.c.out (130 bytes ) - added by bhaible 4 years ago.
Output of the test program
foo.c++.err (1.3 KB ) - added by bhaible 4 years ago.
GCC error messages in C++ mode

Download all attachments as: .zip

Change History (16)

by bhaible, 4 years ago

Attachment: foo.c added

test program

by bhaible, 4 years ago

Attachment: foo.c.out added

Output of the test program

by bhaible, 4 years ago

Attachment: foo.c++.err added

GCC error messages in C++ mode

comment:1 by waddlesplash, 4 years ago

Component: - GeneralSystem/libroot.so

comment:2 by waddlesplash, 4 years ago

Component: System/libroot.soSystem/POSIX

comment:3 by waddlesplash, 4 years ago

Cc: leorize added

leorize, I think you added this file?

comment:4 by bhaible, 4 years ago

As far as I can see from this tracker, it was added by ticket #13954.

comment:5 by pulkomandy, 4 years ago

Partial fix: https://review.haiku-os.org/c/haiku/+/2623

I did not fully implement char16_t. Do we really need it?

comment:6 by tqh, 4 years ago

It is used in UEFI bootloader code.

comment:7 by pulkomandy, 4 years ago

As far as I can see, this header is not used and EFI has its own definition for it.

comment:8 by waddlesplash, 4 years ago

Resolution: fixed
Status: newclosed

Fix merged, but NOT backported to r1beta2 (for now).

comment:9 by bhaible, 4 years ago

The new uchar.h defines the function mbrtoc32 twice. I would guess that this produces a compilation error, both in C mode and in C++ mode. No?

comment:10 by waddlesplash, 4 years ago

Hm, you're right, not sure how I missed that. I'll fix it.

comment:11 by waddlesplash, 4 years ago

Done in hrev54171.

comment:12 by nielx, 4 years ago

Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone

comment:13 by nielx, 4 years ago

Milestone: UnscheduledR1/beta2
Note: See TracTickets for help on using tickets.