[PATCH: assert.h] Suppose nothrow-behaviour of assert-funcs (for g++)

Markus Eisenmann meisenmann.lba@fh-salzburg.ac.at
Thu May 15 12:35:00 GMT 2014


Based on my current findings (I.e., optimizing compiler-output/code) and experiences with lint-checks, 
I have the suggestion to "mark" the inner assert-functions __assert() and __assert_func() with nothrow. 

In most cases the assert-macro is used for debugging (w/o functional need). But in C++ definitions/ 
implementations with nothrow- or noexcept-semantik the GNU C++ compiler adds an exception-guard. 
Assuming that no other "throwing" call is used, this does not appear in a release build. 

Okay, I'm little pedantic about compiler-generated code ... :-) 

IMHO, following patch should applied to newlib's <assert.h> to give the compiler a small "hint", 
that the __assert-funcs does have a nothrow-behaviour (in addition to the noreturn-semantik): 

--- assert.h Tue Oct 16 21:00:30 2012 
+++ assert.h Thu May 15 14:00:48 2014 
@@ -37,7 +37,7 @@ 
#endif /* !NDEBUG */ 

-void _EXFUN(__assert, (const char *, int, const char *) 
+void _EXFUN_NOTHROW(__assert, (const char *, int, const char *) 
_ATTRIBUTE ((__noreturn__))); 
-void _EXFUN(__assert_func, (const char *, int, const char *, const char *) 
+void _EXFUN_NOTHROW(__assert_func, (const char *, int, const char *, const char *) 
_ATTRIBUTE ((__noreturn__))); 

Best regards from Salzburg, 

More information about the Newlib mailing list