The current "fix" for assert.h on vxworks is itself broken in a number of ways.
First, assert.h is special in that it should _not_ have an include guard - the user is allowed to include it multiple times with different definedness of _NDEBUG to enable and disable assert() in parts of a TU. Second, apparently gcc does not implicitly do the extern "C" dance for include-fixed headers, so C++ code ends up with undefined references to _Z8__assertPKc. Third, the ASSERT_STRINGIFY macros are in the user's namespace. Fourth (not strictly a violation), it is a bad idea to macro-expand the test expression, as that can easily lead to completely unreadable gibberish. glibc fixed that in 2015, and incidentally, the original vxworks assert.h also just uses #test. This fixes 1,2 and 4. I still define _ASSERT_H in case somebody has some cpp logic based on whether assert.h has been included at least once. 4 is of course somewhat of a value judgement, but I think it makes sense to be consistent with both the original vxworks header as well as modern glibc. (In extreme cases, it can also save several KBs of precious memory). We still need to stringify __LINE__ since the underlying __assert function just takes a single string, so we can't get completely rid of the stringifying macros. I left the names alone since the risk of clashing with real user code is quite minimal, and somebody might even have used them. 2018-06-07 Rasmus Villemoes <rasmus.villem...@prevas.dk> fixinclude/ * inclhack.def: Fix fixup for assert.h on vxworks. * fixincl.x: Regenerate. --- fixincludes/inclhack.def | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def index 5ec5a50a2e2..c1f5a13eda4 100644 --- a/fixincludes/inclhack.def +++ b/fixincludes/inclhack.def @@ -377,11 +377,15 @@ fix = { mach = "*-*-vxworks*"; replace = <<- _EndOfHeader_ - #ifndef _ASSERT_H + #ifdef _ASSERT_H + #undef _ASSERT_H + #undef assert + #endif + #define _ASSERT_H - #ifdef assert - #undef assert + #ifdef __cplusplus + extern "C" { #endif #if defined(__STDC__) || defined(__cplusplus) @@ -399,11 +403,13 @@ fix = { #define assert(test) ((void) \ ((test) ? ((void)0) : \ - __assert("Assertion failed: " ASSERT_STRINGIFY(test) ", file " \ + __assert("Assertion failed: " #test ", file " \ __FILE__ ", line " ASSERT_STRINGIFY(__LINE__) "\n"))) #endif + #ifdef __cplusplus + } #endif _EndOfHeader_; }; -- 2.15.1