Bug 22985 - -fshort-wchar treated as signed in C++
-fshort-wchar treated as signed in C++
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
All Linux
high Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2000-12-29 11:26 EST by Christopher Blizzard
Modified: 2008-05-01 11:37 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-12-29 11:36:38 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Christopher Blizzard 2000-12-29 11:26:34 EST
From msw's original email:

#include <stdio.h>
#include <stdlib.h>

int main ()
  wchar_t widechars[3] = {(wchar_t)0xFFFD, (wchar_t)0xFFFD, (wchar_t)0xFFFD };

  if (widechars[1] >> 5 != 2047)

  return 0;

[msw@localhost /tmp]$ gcc -fshort-wchar -o test test.c
In file included from test.c:4294967295:
<command line>: warning: "__WCHAR_TYPE__" redefined
[msw@localhost /tmp]$ ./test
[msw@localhost /tmp]$ g++ -fshort-wchar -o test test.c
In file included from test.c:4294967295:
<command line>: warning: "__WCHAR_TYPE__" redefined
[msw@localhost /tmp]$ ./test
Aborted (core dumped)

(the value is -1, or (-3 << 5), as -3 is 0xfffffffd, and is what the
array is initialized to in the C++ case)

In the C++ test, wchar_t is being treated as signed, while in the C
case it is not.  The docs say:

     Override the underlying type for `wchar_t' to be `short unsigned
     int' instead of the default for the target.

... and jakub's response:

There was a typo in cp/decl.c which set C++'s internal wchar_t type to the
opposite sign of what it should have.
I've just commited a fix for this into CVS head and it will make it into
Comment 1 Christopher Blizzard 2000-12-29 11:36:35 EST
And also for reference here's the patch.

Comment 2 Jakub Jelinek 2001-01-21 13:21:23 EST
Fixed in gcc-2.96-70 and above.

Note You need to log in before you can comment on or make changes to this bug.