typedef int wchar_t;

View: New views
10 Messages — Rating Filter:   Alert me  

typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm making wip/icc11 (Intel C++ compiler 11.1) package for NetBSD and I've run into a problem. The C++ compiler fails on

typedef int wchar_t;

line because wchar_t is C++ builtin type and it can't be redefined. On all other BSDs this line is guarded by #ifndef __cplusplus.

http://monkey.org/openbsd/archive2/source-changes/199911/msg00791.html
http://svn.freebsd.org/viewvc/base?view=revision&revision=99640
(dragonflybsd site is currently unvailable)

Is there any reason why there is no __cplusplus guard on NetBSD?

PS the C compiler works fine, I built (with few hacks, though) and ran x11/modular-xorg-server with x11/xf86-video-intel driver and wm/ratpoison.

Thanks,
Alex

Re: typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alexander Nasonov wrote:
> I'm making wip/icc11 (Intel C++ compiler 11.1) package for NetBSD
> and I've run into a problem. The C++ compiler fails on > > typedef
> int wchar_t; > > line because wchar_t is C++ builtin type and it
> can't be redefined. On all other BSDs this line is guarded by
> #ifndef __cplusplus.

After changing 4 files in /usr/include (see the patch below) my
pkgsrc build runs smoothly. I was able to build all www/firefox
dependencies (with PKG_DEFAULT_OPTIONS=-fam).

Thanks,
Alex


Index: include/inttypes.h
===================================================================
RCS file: /cvsroot/src/include/inttypes.h,v
retrieving revision 1.6
diff -u -r1.6 inttypes.h
--- include/inttypes.h 4 Aug 2008 21:19:45 -0000 1.6
+++ include/inttypes.h 1 Nov 2009 12:05:15 -0000
@@ -36,7 +36,7 @@
 #include <sys/inttypes.h>
 #include <machine/ansi.h>
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !(defined(__ICC) && defined(__cplusplus))
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/stddef.h
===================================================================
RCS file: /cvsroot/src/include/stddef.h,v
retrieving revision 1.15
diff -u -r1.15 stddef.h
--- include/stddef.h 21 Aug 2006 16:58:29 -0000 1.15
+++ include/stddef.h 1 Nov 2009 12:05:15 -0000
@@ -45,7 +45,7 @@
 #undef _BSD_SIZE_T_
 #endif
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !(defined(__ICC) && defined(__cplusplus))
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/stdlib.h
===================================================================
RCS file: /cvsroot/src/include/stdlib.h,v
retrieving revision 1.89
diff -u -r1.89 stdlib.h
--- include/stdlib.h 20 Jul 2009 17:03:37 -0000 1.89
+++ include/stdlib.h 1 Nov 2009 12:05:15 -0000
@@ -48,7 +48,7 @@
 #undef _BSD_SIZE_T_
 #endif
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !(defined(__ICC) && defined(__cplusplus))
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/wchar.h
===================================================================
RCS file: /cvsroot/src/include/wchar.h,v
retrieving revision 1.27
diff -u -r1.27 wchar.h
--- include/wchar.h 28 Apr 2008 20:22:54 -0000 1.27
+++ include/wchar.h 1 Nov 2009 12:05:15 -0000
@@ -66,7 +66,7 @@
 
 #include <stdio.h> /* for FILE* */
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !(defined(__ICC) && defined(__cplusplus))
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif

Re: typedef int wchar_t;

by Bugzilla from prlw1@cam.ac.uk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Nov 01, 2009 at 12:11:43PM +0000, Alexander Nasonov wrote:

> Alexander Nasonov wrote:
> > I'm making wip/icc11 (Intel C++ compiler 11.1) package for NetBSD
> > and I've run into a problem. The C++ compiler fails on > > typedef
> > int wchar_t; > > line because wchar_t is C++ builtin type and it
> > can't be redefined. On all other BSDs this line is guarded by
> > #ifndef __cplusplus.
>
> After changing 4 files in /usr/include (see the patch below) my
> pkgsrc build runs smoothly. I was able to build all www/firefox
> dependencies (with PKG_DEFAULT_OPTIONS=-fam).

> +#if defined(_BSD_WCHAR_T_) && !(defined(__ICC) && defined(__cplusplus))

As you say, wchar_t is a C++ builtin type, so why do you bother checking
for __ICC too?

Cheers,

Patrick

Re: typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Patrick Welche wrote:
> As you say, wchar_t is a C++ builtin type, so why do you bother checking
> for __ICC too?

Yes, it's a builtin type and it worries me. Why does g++ compile
it? Something's wrong but I don't know exactly what and why.

PS g++ compiles this typedef only if it appears in a file in a
system directory (-isystem option).

Re: typedef int wchar_t;

by Joerg Sonnenberger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Nov 01, 2009 at 12:11:43PM +0000, Alexander Nasonov wrote:
> After changing 4 files in /usr/include (see the patch below) my
> pkgsrc build runs smoothly. I was able to build all www/firefox
> dependencies (with PKG_DEFAULT_OPTIONS=-fam).

The part adding !defined(__cplusplus) is fine, the part using
!defined(__ICC) is not.

Joerg

Re: typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joerg Sonnenberger wrote:
> The part adding !defined(__cplusplus) is fine, the part using
> !defined(__ICC) is not.

I know it's not right. In fact, I didn't ask NetBSD developers to
commit my patch as-is. I reported what worked. And __ICC is there
because I often compile NetBSD and packages with gcc on the same
box and I didn't want to hit a subtle bug.

But if you believe __cplusplus guard is safe, I'd happy to revert
my local changes.

Thanks,
Alex

Re: typedef int wchar_t;

by Valeriy E. Ushakov-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alexander Nasonov <alnsn@...> wrote:

> Yes, it's a builtin type and it worries me. Why does g++ compile
> it? Something's wrong but I don't know exactly what and why.
>
> PS g++ compiles this typedef only if it appears in a file in a
> system directory (-isystem option).

gnu/dist/gcc4/gcc/cp/parser.c:16280

  /* If the user tries to redeclare bool or wchar_t (with, for
     example, in "typedef int wchar_t;") we remember that this is what
     happened.  In system headers, we ignore these declarations so
     that G++ can work with system headers that are not C++-safe.  */


SY, Uwe
--
uwe@...                       |       Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/          |       Ist zu Grunde gehen


Re: typedef int wchar_t;

by Joerg Sonnenberger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 05, 2009 at 12:28:09AM +0000, Alexander Nasonov wrote:

> Joerg Sonnenberger wrote:
> > The part adding !defined(__cplusplus) is fine, the part using
> > !defined(__ICC) is not.
>
> I know it's not right. In fact, I didn't ask NetBSD developers to
> commit my patch as-is. I reported what worked. And __ICC is there
> because I often compile NetBSD and packages with gcc on the same
> box and I didn't want to hit a subtle bug.
>
> But if you believe __cplusplus guard is safe, I'd happy to revert
> my local changes.

I don't think we care much about ancient versions of G++ and if someone
does, it should take GCC version check, nothing else.

Joerg

Re: typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joerg Sonnenberger wrote:
> I don't think we care much about ancient versions of G++ and if someone
> does, it should take GCC version check, nothing else.

One potential problem with the check is that ICC defines gcc macros
unless you pass -no-gcc.
wip/icc11 depends on lang/gcc34 which I believe is not ancient in
this respect.

Thanks,
Alex

Re: typedef int wchar_t;

by alnsn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joerg Sonnenberger wrote:
> I don't think we care much about ancient versions of G++ and if someone
> does, it should take GCC version check, nothing else.

Sorry for the late reply, I totally forgot about this topic until
I started rebuiling all packages with a newer version of icc.

All gcc versions up to 2.95 support native wchar_t in C++ mode.
It looks like we don't need a version check at all.

$ cat /tmp/w.cpp                                          
int main() { wchar_t x = 0; return x; }
$ /usr/pkg/gcc-2.95.3/bin/g++ -c -o /tmp/w.o /tmp/w.cpp  
$ echo $?
0

Index: include/inttypes.h
===================================================================
RCS file: /cvsroot/src/include/inttypes.h,v
retrieving revision 1.6
diff -u -r1.6 inttypes.h
--- include/inttypes.h 4 Aug 2008 21:19:45 -0000 1.6
+++ include/inttypes.h 15 Nov 2009 21:17:38 -0000
@@ -36,7 +36,7 @@
 #include <sys/inttypes.h>
 #include <machine/ansi.h>
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/stddef.h
===================================================================
RCS file: /cvsroot/src/include/stddef.h,v
retrieving revision 1.15
diff -u -r1.15 stddef.h
--- include/stddef.h 21 Aug 2006 16:58:29 -0000 1.15
+++ include/stddef.h 15 Nov 2009 21:17:38 -0000
@@ -45,7 +45,7 @@
 #undef _BSD_SIZE_T_
 #endif
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/stdlib.h
===================================================================
RCS file: /cvsroot/src/include/stdlib.h,v
retrieving revision 1.89
diff -u -r1.89 stdlib.h
--- include/stdlib.h 20 Jul 2009 17:03:37 -0000 1.89
+++ include/stdlib.h 15 Nov 2009 21:17:38 -0000
@@ -48,7 +48,7 @@
 #undef _BSD_SIZE_T_
 #endif
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif
Index: include/wchar.h
===================================================================
RCS file: /cvsroot/src/include/wchar.h,v
retrieving revision 1.27
diff -u -r1.27 wchar.h
--- include/wchar.h 28 Apr 2008 20:22:54 -0000 1.27
+++ include/wchar.h 15 Nov 2009 21:17:39 -0000
@@ -66,7 +66,7 @@
 
 #include <stdio.h> /* for FILE* */
 
-#ifdef _BSD_WCHAR_T_
+#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
 typedef _BSD_WCHAR_T_ wchar_t;
 #undef _BSD_WCHAR_T_
 #endif