Bug 22985

Summary: -fshort-wchar treated as signed in C++
Product: [Retired] Red Hat Linux Reporter: Christopher Blizzard <blizzard>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 7.0CC: dbaron, msw
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-12-29 16:36:38 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christopher Blizzard 2000-12-29 16:26:34 UTC
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)
      abort();

  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:

`-fshort-wchar'
     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
gcc-c++-2.96-70.

Comment 1 Christopher Blizzard 2000-12-29 16:36:35 UTC
And also for reference here's the patch.

http://gcc.gnu.org/ml/gcc-patches/2000-12/msg01369.html

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