LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
lf_assert.h
1
9#ifndef c3c605c9e48646758bf03fab65d52836
10#define c3c605c9e48646758bf03fab65d52836
11
12#include <boost/assert.hpp>
13#include <sstream>
14#include <stdexcept>
15#include <string>
16
17namespace lf::base {
18
19void AssertionFailed(const std::string& expr, const std::string& file,
20 long line, const std::string& msg);
21
22} // namespace lf::base
23
29#define LF_UNREACHABLE \
30 { \
31 ::lf::base::AssertionFailed("false", __FILE__, __LINE__, ""); \
32 std::abort(); \
33 }
34
44// NOLINTBEGIN(readability-simplify-boolean-expr)
45#define LF_VERIFY_MSG(expr, msg) \
46 { \
47 if (!(expr)) { \
48 std::stringstream ss; \
49 ss << msg; /* NOLINT */ \
50 ::lf::base::AssertionFailed(#expr, __FILE__, __LINE__, ss.str()); \
51 throw std::runtime_error("this code should not be reached"); \
52 } \
53 }
54// NOLINTEND(readability-simplify-boolean-expr)
55
56#ifdef NDEBUG
57#define LF_ASSERT_MSG_CONSTEXPR(expr, msg) ((void)0)
58#define LF_ASSERT_MSG(expr, msg) ((void)0)
59#else
60#define LF_ASSERT_MSG_CONSTEXPR(expr, msg) \
61 { \
62 if (!(expr)) throw std::runtime_error(msg); \
63 }
64
65// NOLINTBEGIN(readability-simplify-boolean-expr)
66#define LF_ASSERT_MSG(expr, msg) \
67 { \
68 if (!(expr)) { \
69 std::stringstream ss; \
70 ss << msg; /* NOLINT */ \
71 ::lf::base::AssertionFailed(#expr, __FILE__, __LINE__, ss.str()); \
72 LF_UNREACHABLE; \
73 } \
74 }
75#endif
76// NOLINTEND(readability-simplify-boolean-expr)
77
78// And now we will redefine eigen_assert if needed:
79#ifdef LF_REDIRECT_ASSERTS
80#ifdef eigen_assert
81#ifndef eigen_assert_redirected
82// eigen_assert has already been defined, but not by us!
83#ifdef _MSC_VER
84#pragma message( \
85 "WARNING: Eigen has been included before all LehrFEM++ headers but LF_REDIRECT_ASSERTS=On in cmake. Not all Eigen Asserts may print a stacktrace! https://craffael.github.io/lehrfempp/eigen_stacktrace_warning.html")
86#else
87#warning \
88 "Eigen has been included before all LehrFEM++ headers but LF_REDIRECT_ASSERTS=On in cmake. Not all Eigen Asserts may print a stacktrace! https://craffael.github.io/lehrfempp/eigen_stacktrace_warning.html"
89#endif
90#undef eigen_assert
91#define eigen_assert(x) LF_ASSERT_MSG(x, "")
92#define eigen_assert_redirected
93#endif
94#else
95#define eigen_assert(x) LF_ASSERT_MSG(x, "")
96#define eigen_assert_redirected
97#endif
98#endif
99#endif // c3c605c9e48646758bf03fab65d52836
Contains basic functionality that is used by other parts of LehrFEM++.
Definition base.h:15
void AssertionFailed(const std::string &expr, const std::string &file, long line, const std::string &msg)
Definition lf_assert.cc:12