aboutsummaryrefslogtreecommitdiff
path: root/libcpp/include
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp/include')
-rw-r--r--libcpp/include/line-map.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index edcbdc9bd66..48a5dec31e0 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -579,6 +579,16 @@ bool linemap_location_from_macro_expansion_p (const struct line_maps *,
if (! (EXPR)) \
abort (); \
} while (0)
+
+/* Assert that becomes a conditional expression when checking is disabled at
+ compilation time. Use this for conditions that should not happen but if
+ they happen, it is better to handle them gracefully rather than crash
+ randomly later.
+ Usage:
+
+ if (linemap_assert_fails(EXPR)) handle_error(); */
+#define linemap_assert_fails(EXPR) __extension__ \
+ ({linemap_assert (EXPR); false;})
/* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */
@@ -588,6 +598,7 @@ bool linemap_location_from_macro_expansion_p (const struct line_maps *,
#else
/* Include EXPR, so that unused variable warnings do not occur. */
#define linemap_assert(EXPR) ((void)(0 && (EXPR)))
+#define linemap_assert_fails(EXPR) (! (EXPR))
#define linemap_check_ordinary(LINE_MAP) (LINE_MAP)
#endif