assert.hh (1072B)
1 #ifndef assert_hh_INCLUDED 2 #define assert_hh_INCLUDED 3 4 namespace Kakoune 5 { 6 7 class StringView; 8 9 // return true if user asked to ignore the error 10 bool notify_fatal_error(StringView message); 11 12 void on_assert_failed(const char* message); 13 14 } 15 16 #define STRINGIFY(X) #X 17 #define TOSTRING(X) STRINGIFY(X) 18 19 #ifdef KAK_DEBUG 20 #define kak_assert(...) do { \ 21 if (not (__VA_ARGS__)) \ 22 on_assert_failed("assert failed \"" #__VA_ARGS__ \ 23 "\" at " __FILE__ ":" TOSTRING(__LINE__)); \ 24 } while (false) 25 26 #define kak_expect_throw(exception_type, ...) try {\ 27 __VA_ARGS__; \ 28 on_assert_failed("expression \"" #__VA_ARGS__ \ 29 "\" did not throw \"" #exception_type \ 30 "\" at " __FILE__ ":" TOSTRING(__LINE__)); \ 31 } catch (exception_type &err) {} 32 #else 33 #define kak_assert(...) do { (void)alignof(decltype(__VA_ARGS__)); } while(false) 34 #define kak_expect_throw(_, ...) do { (void)alignof(decltype(__VA_ARGS__)); } while(false) 35 #endif 36 37 38 #endif // assert_hh_INCLUDED