__STDC_VERSION__ isn't defined for __cplusplus, so we've been removing
such checks. Some got missed.
Stop defining __func__ and just use the __PRETTY_FUNCTION__ GCC extension
in <assert.h>. Also fix the #if there so that C++ gets __assert2 rather
than __assert, and rewrite the cast to work with -I rather than -isystem.
Also remove __restrict and just always use the __restrict GCC extension.
Add a trivial test for <assert.h>.
Bug: http://b/30353757
Change-Id: Ie49bb417976293d3a9692b516e28fe3c0ae0a6d9
Test: ran bionic unit tests.
Add C11 static_assert to <assert.h>. Remove uses of __dead while we're there:
__noreturn already does the same thing on those functions.
Fix <uchar.h> so it works from C.
<stdalign.h> and <stdnoreturn.h> are provided by clang, so there's nothing
for us to do.
Bug: http://b/29178582
Change-Id: Iebc46223868729a26d1a61eb125b76cbcb83a22d
These functions should print assertion violation messages and then
call abort(). They do really not return control flow afterwards.
Consider the declaration of the similar __assert_fail from glibc:
extern void __assert_fail (const char *__assertion,
const char *__file,
unsigned int __line,
const char *__function)
__THROW __attribute__ ((__noreturn__));
Bionic has __noreturn defined in sys/cdefs.h to be that GNU
noreturn attribute.
This patch has a practical value. Consider the following function:
void check(void* ptr) {
assert(ptr != NULL);
}
Without this patch applied, gcc (and presumably clang) shows even in
debug mode:
warning: unused parameter 'ptr' [-Wunused-parameter]
In release mode, NDEBUG is defined and assert() becomes a no-op, as
one should expect. Thus, the warning is shown correctly then.
Another code sample:
float array[2];
int i = 3;
...
assert(i < 2);
array[i] = 0;
gcc says,
warning: array subscript is below array bounds [-Warray-bounds]
In other words, without noreturn attribute, assertions do not
allow a compiler's static analyzer to properly understand
the preconditions.
Change-Id: I3be92e99787c528899cf243ed448c4730c00c45b
Signed-off-by: Vadim Markovtsev <gmarkhor@gmail.com>