summaryrefslogtreecommitdiff
path: root/assert/assert.h
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-08-21 13:03:29 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-08-21 15:33:11 +0200
commitb5889d25e9bf944a89fdd7bcabf3b6c6f6bb6f7c (patch)
tree93b8e344470970e6c9431c46cc2d251cd22a0b06 /assert/assert.h
parent41e673c1e771075f413f8e8ecd9e108f5ae096d9 (diff)
assert: Support types without operator== (int) [BZ #21972]
Diffstat (limited to 'assert/assert.h')
-rw-r--r--assert/assert.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/assert/assert.h b/assert/assert.h
index 6801cfeb10..640c95c063 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 <bool> (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 \