Andrew Haley wrote:
Peter A. Felvegi wrote:
Ian Lance Taylor wrote:
You can avoid this kind of thing by telling gcc that your assert
condition does not return.
void assert_failure () __attribute__ ((noreturn, always_inline));
void assert_failure() { __asm__ ("int $0x03"); }
#define ASSERT(x) if (x) { } else { assert_failure(); }
Now I got 'noreturn function does return' warning/error in
assert_failure().
void assert_failure() {
for (;;)
__asm__ ("int $0x03");
}
Remarks:
1) I defined the fn as 'inline void assert_failure()' otherwise the
debug link would fail with 'multiple definitions' error, despite the
'always_inline' attribute.
2) when compiling some template functions with optimization, I got
"sorry, unimplemented: inlining failed in call to ‘void
assert_failure()’: function not inlinable" messages, so I had to remove
the always_inline attribute.
3) the for(;;) loop solves the above 'noreturn function does return'
error, but it also prohibits continuing the prg from the debugger. I
Solved this by only defining the assert_failure() fn in optimized
builds, the debug build uses the asm directly in the assert macro.
Thanks, Peter