GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 47599 - -fno-short-wchar does not force long wchar
Summary: -fno-short-wchar does not force long wchar
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-03 15:34 UTC by Bastien ROUCARIES
Modified: 2012-11-12 20:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bastien ROUCARIES 2011-02-03 15:34:35 UTC
if WCHAR_TYPE is "short int" (cygwin) the following program produce always short wchar. Please treat this option like -fno-short-enum

#include <wchar.h>
int x = sizeof (wchar_t);

$ gcc -S -o - foo.c
$ gcc -fshort-wchar -S -o - foo.c
$ gcc -fno-short-wchar -S -o - foo.c
Comment 1 Andrew Pinski 2011-02-03 18:51:51 UTC
This is a header issue which means it is not a GCC bug.
Comment 2 Bastien ROUCARIES 2011-02-04 08:21:20 UTC
I disagree

wchar_t is a building type. Indeed L"aa" should expand to 16 bits packed char with short wchar and 32 bits with no-short-wchar.

Due to the LNaaN constant specification wchar_t is more than a typedef stuff.

Bastien
Comment 3 Bastien ROUCARIES 2011-02-04 08:27:40 UTC
BTW i have checked the source code, and if my memory is correct wchar_t is defined as
MODIFIED_WCHAR_T = fshortwchar ? "Short int" : WCHAR_T

Where wchar_t is defined by the architecture config.

The problem is under arch where WCHAR_T is "short int" this flag have no effect. This flag should behave as short-enum where arch specify a default that could be overwritten

Bastien
Comment 4 Andrew Pinski 2011-02-04 08:33:03 UTC
It is a builtin type (for C++ it is exposed as the keyword, wchar_t). For C, the headers define the type, see the preprocessed source to show that is the case.
Comment 5 Bastien ROUCARIES 2011-02-04 09:25:36 UTC
ok thanks it is defined in the header and in this case they are two bugs.

Try the following program

#include <stdio.h>
typedef __WCHAR_TYPE__ wchar_t;
wchar_t a[] = L"aa";
int s  = sizeof(wchar_t);

void main()
{
  printf("%i\n",s);
}

under linux it output 4
under linux with -fno-short-char it output 4
under linux with -fshort-char it output 2

under cygwin it output 2
nder linux with -fno-short-char it output 2 (BUG here)
under linux with -fshort-char it output 2
Comment 6 Bastien ROUCARIES 2011-02-04 09:39:02 UTC
I have checked with gcc -E the following program:

typedef __WCHAR_TYPE__ wchar_t;

under linux it output typedef int wchar_t
under linux with -fno-short-char it output typedef int wchar_t
under linux with -fshort-char it output typedef short unsigned int wchar_t

under cygwin it output typedef short unsigned int wchar_t
nder linux with -fno-short-char it output typedef short unsigned int wchar_t (BUG)
under linux with -fshort-char it output typedef short unsigned int wchar_t

Bastien
Comment 7 Bastien ROUCARIES 2011-02-04 09:41:04 UTC
Sorry replace the last linux by cygwin
Comment 8 Bastien ROUCARIES 2011-06-10 10:14:06 UTC
Any news of this bug ?
Comment 9 Earnie 2012-11-12 20:15:07 UTC
Looking at http://msdn.microsoft.com/en-us/library/dh8che7s(v=vs.71).aspx I see that wchar_t is "typically" defined as "unsigned short".  MSVC provides a /Zc:wchar_t that causes wchar_t to become "a native type" that maps to _wchar_t.

Currently the mingw.org wchar.h file includes the stddef.h file after defining __need_wchar_t.  I need to walk through stddef.h to determine if we (mingw.org) needs to define some other macro based on the provided options.  However, I'm feeling like this will be a coordinated effort between both parties.  I don't know about Cygwin's versions of the headers, they should match more to what Linux defines.