From 08dbe1eea3593cf640d3ad45b74ecb09cc9967d4 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 24 Aug 2021 18:35:01 -0500 Subject: [PATCH] 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. --- ORCACDefs/assert.h | 11 ++++++++--- cc.notes | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ORCACDefs/assert.h b/ORCACDefs/assert.h index 7c04dbc..7622586 100644 --- a/ORCACDefs/assert.h +++ b/ORCACDefs/assert.h @@ -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 diff --git a/cc.notes b/cc.notes index 45e9159..a9d285e 100644 --- a/cc.notes +++ b/cc.notes @@ -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.