Bug 160294 - [headers] [patch] missing cast in "/usr/include/assert.h" v 1.4 2002/03/23 17:24:53
Summary: [headers] [patch] missing cast in "/usr/include/assert.h" v 1.4 2002/03/23 17...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-29 20:20 UTC by Abe
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments
file.diff (612 bytes, patch)
2011-08-29 20:20 UTC, Abe
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Abe 2011-08-29 20:20:09 UTC
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.

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:
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__)))
                 ^ ~
Comment 1 Xin LI 2011-09-09 22:53:26 UTC
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
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:20 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped