Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-23 18:45:44 +0300
committerJacques Lucke <jacques@blender.org>2021-03-23 18:45:44 +0300
commit433fb9326ece7b0b84f2f548e43059881cca68b5 (patch)
treefdfaf85e5e41b2f2c7d1182b68fc985dc436a221 /source/blender/blenlib/BLI_assert.h
parent7046e37eded55ac8879835500788a1e734437bbf (diff)
BLI: add macro to indicate unreachable code
This adds a `BLI_assert_unreachable()` macro, that should be used instead of `BLI_assert(false)` in many places. * `BLI_assert_unreachable` provides more information than `BLI_assert(false)` to people reading the code. * `BLI_assert_unreachable` will print an error to `stderr` in a release build. This makes it more likely that we will get bug reports when the assumptions of a developer were wrong. Differential Revision: https://developer.blender.org/D10780
Diffstat (limited to 'source/blender/blenlib/BLI_assert.h')
-rw-r--r--source/blender/blenlib/BLI_assert.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h
index 172a2fb44ca..685f526b4ad 100644
--- a/source/blender/blenlib/BLI_assert.h
+++ b/source/blender/blenlib/BLI_assert.h
@@ -33,6 +33,7 @@ extern "C" {
void _BLI_assert_print_pos(const char *file, const int line, const char *function, const char *id);
void _BLI_assert_print_backtrace(void);
void _BLI_assert_abort(void);
+void _BLI_assert_unreachable_print(const char *file, const int line, const char *function);
#ifdef _MSC_VER
# include <crtdbg.h> /* for _STATIC_ASSERT */
@@ -88,6 +89,17 @@ void _BLI_assert_abort(void);
#define BLI_STATIC_ASSERT_ALIGN(st, align) \
BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned")
+/**
+ * Indicates that this line of code should never be executed. If it is reached, it will abort in
+ * debug builds and print an error in release builds.
+ */
+#define BLI_assert_unreachable() \
+ { \
+ _BLI_assert_unreachable_print(__FILE__, __LINE__, __func__); \
+ BLI_assert(!"This line of code is marked to be unreachable."); \
+ } \
+ ((void)0)
+
#ifdef __cplusplus
}
#endif