[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 46823b7 3/3: Rewrite "assert" macros to permi
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 46823b7 3/3: Rewrite "assert" macros to permit better compiler diagnostics |
Date: |
Mon, 10 Jun 2019 12:34:55 -0400 (EDT) |
branch: master
commit 46823b7245a0ba214463ffc482fe9805d519ef5b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Rewrite "assert" macros to permit better compiler diagnostics
---
assert_lmi.hpp | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/assert_lmi.hpp b/assert_lmi.hpp
index be38ca7..a308005 100644
--- a/assert_lmi.hpp
+++ b/assert_lmi.hpp
@@ -38,6 +38,14 @@
/// macro is appropriate only for lightweight assertions that should
/// be left in released code.
///
+/// The logic could more plainly be expressed as
+/// if(!(condition)) {throw...}
+/// but is instead written as
+/// if(condition) {} else {throw...}
+/// which, by avoiding an extra level of parentheses, helps compilers
+/// give better diagnostics--see:
+/// https://lists.nongnu.org/archive/html/lmi/2019-06/msg00010.html
+///
/// The last line eats a semicolon written after the macro invocation.
///
/// For a more-elaborate runtime-error facility, see 'alert*.?pp'.
@@ -45,7 +53,10 @@
#define LMI_ASSERT(condition) \
do \
{ \
- if(!(condition)) \
+ if(condition) \
+ { \
+ } \
+ else \
{ \
std::ostringstream assert_message; \
assert_message \
@@ -67,7 +78,10 @@
#define LMI_ASSERT_WITH_MSG(condition,message) \
do \
{ \
- if(!(condition)) \
+ if(condition) \
+ { \
+ } \
+ else \
{ \
std::ostringstream assert_message; \
assert_message \