From nobody@FreeBSD.org  Mon Aug 29 19:10:52 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 259361065670
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 29 Aug 2011 19:10:52 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id F02598FC1B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 29 Aug 2011 19:10:51 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p7TJApdl036722
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 29 Aug 2011 19:10:51 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p7TJApQa036721;
	Mon, 29 Aug 2011 19:10:51 GMT
	(envelope-from nobody)
Message-Id: <201108291910.p7TJApQa036721@red.freebsd.org>
Date: Mon, 29 Aug 2011 19:10:51 GMT
From: Abe <abe_skolnik@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: missing cast in "/usr/include/assert.h" v 1.4 2002/03/23 17:24:53
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         160294
>Category:       kern
>Synopsis:       [headers] [patch] missing cast in "/usr/include/assert.h" v 1.4 2002/03/23 17:24:53
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 29 19:20:09 UTC 2011
>Closed-Date:    
>Last-Modified:  Fri Sep  9 22:00:25 UTC 2011
>Originator:     Abe
>Release:        Mac OS X Server 10.6.5  ;-)
>Organization:
TAMU
>Environment:
Darwin [hostname] 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov  5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386 i386
>Description:
The "/usr/include/assert.h" from FreeBSD causes C++ compilation to fail when an assertion is done and the compiler is non-GCC _and_ does not define "__GNUC__" _and_ "NDEBUG" is not defined.  It`s a simple and quick fix.


>How-To-Repeat:
compile this:

#include <cassert>
int main() {
  assert(1);
}

like this [assuming Clang is installed and is on the PATH]:

clang++ -U__GNUC__ test.cpp

 and one of the errors you get is this:

test.cpp:3:3: error: right operand to ? is void, but left operand is of type 'int'
  assert(1);
  ^~~~~~~~~
In file included from test.cpp:1:
In file included from /usr/include/c++/4.2.1/cassert:48:
/usr/include/assert.h:69:18: note: instantiated from:
    ((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__)))
                 ^ ~
>Fix:
*** /usr/include/assert.h       2009-10-02 01:24:01.000000000 -0500
--- /tmp/assert.h___new 2011-08-28 21:39:12.000000000 -0500
***************
*** 66,72 ****
  __END_DECLS

  #define assert(e)  \
!     ((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__)))
  #define __assert(e, file, line) \
      ((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())

--- 66,72 ----
  __END_DECLS

  #define assert(e)  \
!     ((void) ((e) ? ((void)0) : __assert (#e, __FILE__, __LINE__)))
  #define __assert(e, file, line) \
      ((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())
q

Patch attached with submission follows:

*** /usr/include/assert.h	2009-10-02 01:24:01.000000000 -0500
--- /tmp/assert.h___new	2011-08-28 21:39:12.000000000 -0500
***************
*** 66,72 ****
  __END_DECLS
  
  #define assert(e)  \
!     ((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__)))
  #define __assert(e, file, line) \
      ((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())
  
--- 66,72 ----
  __END_DECLS
  
  #define assert(e)  \
!     ((void) ((e) ? ((void)0) : __assert (#e, __FILE__, __LINE__)))
  #define __assert(e, file, line) \
      ((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())
  


>Release-Note:
>Audit-Trail:

From: Xin LI <delphij@delphij.net>
To: Abe <abe_skolnik@yahoo.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/160294: missing cast in "/usr/include/assert.h" v 1.4 2002/03/23
 17:24:53
Date: Fri, 09 Sep 2011 14:53:26 -0700

 I don't think this is a FreeBSD bug, I've checked FreeBSD code revision
 history and we never shipped an assert.h with 0 not being properly
 casted to void.
 
 Your code will not compile on FreeBSD for another reason which we need
 to fix anyways, thanks for letting us know this!
 
 Cheers,
 -- 
 Xin LI <delphij@delphij.net>	https://www.delphij.net/
 FreeBSD - The Power to Serve!		Live free or die
>Unformatted:
