From b5889d25e9bf944a89fdd7bcabf3b6c6f6bb6f7c Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 21 Aug 2017 13:03:29 +0200 Subject: assert: Support types without operator== (int) [BZ #21972] --- assert/assert.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'assert/assert.h') diff --git a/assert/assert.h b/assert/assert.h index 6801cfe..640c95c 100644 --- a/assert/assert.h +++ b/assert/assert.h @@ -85,7 +85,12 @@ __END_DECLS /* When possible, define assert so that it does not add extra parentheses around EXPR. Otherwise, those added parentheses would suppress warnings we'd expect to be detected by gcc's -Wparentheses. */ -# if !defined __GNUC__ || defined __STRICT_ANSI__ +# if defined __cplusplus +# define assert(expr) \ + (static_cast (expr) \ + ? void (0) \ + : __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION)) +# elif !defined __GNUC__ || defined __STRICT_ANSI__ # define assert(expr) \ ((expr) \ ? __ASSERT_VOID_CAST (0) \ @@ -93,12 +98,11 @@ __END_DECLS # else /* The first occurrence of EXPR is not evaluated due to the sizeof, but will trigger any pedantic warnings masked by the __extension__ - for the second occurrence. The explicit comparison against zero is - required to support function pointers and bit fields in this - context, and to suppress the evaluation of variable length - arrays. */ + for the second occurrence. The ternary operator is required to + support function pointers and bit fields in this context, and to + suppress the evaluation of variable length arrays. */ # define assert(expr) \ - ((void) sizeof ((expr) == 0), __extension__ ({ \ + ((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \ if (expr) \ ; /* empty */ \ else \ -- cgit v1.1