Include the function name in assertion failure messages.

This is required by C99 and later, enabled by the availability of __func__.

This requires an updated assertion-printing function in ORCALib. Unfortunately, GNO has the assertion-printing function in its libc rather than in ORCALib, because it calls the GNO implementation of stdio. Therefore, we continue to use the old form under GNO for now, to maintain compatibility with its existing libc.
This commit is contained in:
Stephen Heumann 2021-08-24 18:35:01 -05:00
parent aa5b239824
commit 08dbe1eea3
2 changed files with 10 additions and 5 deletions

View File

@ -15,15 +15,20 @@
#endif
#ifndef NDEBUG
#define assert(expression) (expression) ? ((void) 0) : (__assert(__FILE__, __LINE__, #expression))
#ifndef __GNO__
#define assert(expression) (expression) ? ((void) 0) : (__assert2(__FILE__, __LINE__, __func__, #expression))
#else
#define assert(expression) ((void) 0)
#define assert(expression) (expression) ? ((void) 0) : (__assert(__FILE__, __LINE__, #expression))
#endif
#else
#define assert(expression) ((void)0)
#endif
#ifndef __assert__
#define __assert__
extern void __assert(char *, int, char *);
extern void __assert(const char *, unsigned, const char *);
extern void __assert2(const char *, unsigned, const char *, const char *);
#define static_assert _Static_assert

View File

@ -244,9 +244,9 @@ p. 343
The documentation states that assert() uses exit(-1) to exit a program. Actually, it uses abort().
Beginning with ORCA/C 2.1, assert() prints a string that includes the assertion itself, not just the line number and file name. The assertion has the form
Beginning with ORCA/C 2.1, assert() prints a string that includes the assertion itself, not just the line number and file name. Beginning with ORCA/C 2.2.0 B5, it also includes the name of the enclosing function. The assertion has the form
Assertion failed: file :hd:foo.cc, line 47; assertion: bar==1
Assertion failed: file :hd:foo.cc, line 47, function fn; assertion: bar==1
The documentation states assert() writes to stdout. Beginning with ORCA/C 2.1, it writes to stderr.