[12756de] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
[4f147cc] | 6 | // |
---|
| 7 | // assert.h -- |
---|
| 8 | // |
---|
[12756de] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Thu Aug 18 13:19:26 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[d6c1dd0] | 12 | // Last Modified On : Tue Aug 1 11:56:01 2017 |
---|
| 13 | // Update Count : 16 |
---|
[4f147cc] | 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
[bf2438c] | 17 | // Pragmas for header cleanup tool |
---|
| 18 | // IWYU pragma: private, include <cassert> |
---|
[12756de] | 19 | |
---|
[e59c088] | 20 | #include_next <cassert> |
---|
[12756de] | 21 | |
---|
[733074e] | 22 | #include <string> |
---|
| 23 | |
---|
| 24 | template < typename ... Params > |
---|
| 25 | std::string toString( const Params & ... params ); |
---|
| 26 | |
---|
[e59c088] | 27 | #ifdef NDEBUG |
---|
[12756de] | 28 | |
---|
[e59c088] | 29 | #define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0)) |
---|
| 30 | |
---|
| 31 | #else |
---|
| 32 | |
---|
| 33 | #define assertf(expr, fmt, ...) ((expr) \ |
---|
| 34 | ? (__ASSERT_VOID_CAST (0)) \ |
---|
| 35 | : __assert_fail_f( #expr, __FILE__, __LINE__, \ |
---|
| 36 | __ASSERT_FUNCTION, fmt, ## __VA_ARGS__ )) |
---|
| 37 | |
---|
[e3e16bc] | 38 | void __assert_fail_f( const char *assertion, const char *file, |
---|
| 39 | unsigned int line, const char *function, |
---|
| 40 | const char *fmt, ... |
---|
[e59c088] | 41 | ) __attribute__((noreturn, format(printf, 5, 6))); |
---|
| 42 | |
---|
| 43 | #endif |
---|
[12756de] | 44 | |
---|
[4f147cc] | 45 | template<typename T, typename U> |
---|
[e3e16bc] | 46 | static inline T strict_dynamic_cast( const U & src ) { |
---|
[4f147cc] | 47 | T ret = dynamic_cast<T>(src); |
---|
[be151bf] | 48 | assertf(ret, "%s", toString(src).c_str()); |
---|
[4f147cc] | 49 | return ret; |
---|
| 50 | } |
---|
| 51 | |
---|
[6a625de] | 52 | extern void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2))); |
---|
[12756de] | 53 | // Local Variables: // |
---|
| 54 | // tab-width: 4 // |
---|
| 55 | // mode: c++ // |
---|
| 56 | // compile-command: "make install" // |
---|
| 57 | // End: // |
---|