This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
preprocessor/8880: __WCHAR_TYPE__ macro incorrectly set to "long int" with -fshort-wchar
- From: cheinan at primus dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 9 Dec 2002 20:17:45 -0000
- Subject: preprocessor/8880: __WCHAR_TYPE__ macro incorrectly set to "long int" with -fshort-wchar
- Reply-to: cheinan at primus dot com
>Number: 8880
>Category: preprocessor
>Synopsis: __WCHAR_TYPE__ macro incorrectly set to "long int" with -fshort-wchar
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Dec 09 12:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Cheinan Marks
>Release: gcc version 3.2.1
>Organization:
>Environment:
Sun Solaris 8 Sparc
liza:~/test> g++ -v
Reading specs from /opt/exp/full/lib/gcc-lib/sparc-sun-solaris2.8/3.2.1/specs
Configured with: ../gcc-3.2.1/configure --prefix=/opt/exp/full --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls --enable-languages=c,c++
Thread model: posix
gcc version 3.2.1
>Description:
The __WCHAR_TYPE__ macro is not set correctly when the -fshort-wchar command line option is specified. In gcc 3.0.3 the macro would be defined to "unsigned short," but in 3.2.1 it remains set to "long int." The wchar_t type itself is correct.
The compiler also emits the diagnostic:
<command line>:1:1: warning: "__WCHAR_TYPE__" redefined
<command line>:1:1: warning: this is the location of the previous definition
>How-To-Repeat:
liza:~/test> cat empty.cpp
int main()
{
return 0;
}
liza:~/test> g++ -E -dM -fshort-wchar empty.cpp
<command line>:1:1: warning: "__WCHAR_TYPE__" redefined
<command line>:1:1: warning: this is the location of the previous definition
#define __EXTENSIONS__ 1
#define __HAVE_BUILTIN_SETJMP__ 1
#define _XOPEN_SOURCE 500
#define __sparc 1
#define sun 1
#define __unix__ 1
#define unix 1
#define __SIZE_TYPE__ unsigned int
#define __GNUC_PATCHLEVEL__ 1
#define sparc 1
#define __unix 1
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __USER_LABEL_PREFIX__
#define __STDC_HOSTED__ 1
#define _LARGEFILE64_SOURCE 1
#define __EXCEPTIONS 1
#define __GXX_WEAK__ 1
#define __WCHAR_TYPE__ long int
#define _LARGEFILE_SOURCE 1
#define __WINT_TYPE__ long int
#define __GNUC__ 3
#define __sun__ 1
#define __SVR4 1
#define __GCC_NEW_VARARGS__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __svr4__ 1
#define __GNUG__ 3
#define __sparc__ 1
#define __GXX_ABI_VERSION 102
#define __GNUC_MINOR__ 2
#define __PTRDIFF_TYPE__ int
#define __sun 1
#define __REGISTER_PREFIX__
#define __NO_INLINE__ 1
#define __VERSION__ "3.2.1"
Alternative illustration:
> cat wcharmacro.cpp
#include <iostream>
int main()
{
std::cout << "sizeof(__WCHAR_TYPE__) = " << sizeof(__WCHAR_TYPE__) << std::endl;
std::cout << "sizeof(wchar_t) = " << sizeof(wchar_t) << std::endl;
return 0;
}
> g++ wcharmacro.cpp -fshort-wchar -owcm -Wl,-R/opt/exp/full/lib
<command line>:1:1: warning: "__WCHAR_TYPE__" redefined
<command line>:1:1: warning: this is the location of the previous definition
> ./wcm
sizeof(__WCHAR_TYPE__) = 4
sizeof(wchar_t) = 2
>Fix:
Workaround: Add a -D__WCHAR_TYPE__=whatever after the -fshort-wchar on the command line.
Better fix: Add a macro that defines to a string that tells whether the -fshort-wchar is present.
>Release-Note:
>Audit-Trail:
>Unformatted: