source: src/include/cassert @ 9317419

ADTast-experimental
Last change on this file since 9317419 was 9feb34b, checked in by Andrew Beach <ajbeach@…>, 20 months ago

Moved toString and toCString to a new header. Updated includes. cassert was somehow getting instances of toString before but that stopped working so I embedded the new smaller include.

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[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
[f685679]11// Last Modified By : Andrew Beach
[dafe9e1]12// Last Modified On : Mon Jun  3 13:11:00 2017
13// Update Count     : 18
[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
[9feb34b]22#include "Common/ToString.hpp"
[733074e]23
[e59c088]24#ifdef NDEBUG
[12756de]25
[e59c088]26#define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0))
27
28#else
29
30#define assertf(expr, fmt, ...) ((expr) \
31        ? (__ASSERT_VOID_CAST (0)) \
32        : __assert_fail_f( #expr, __FILE__, __LINE__, \
33        __ASSERT_FUNCTION, fmt, ## __VA_ARGS__ ))
34
[e3e16bc]35void __assert_fail_f(   const char *assertion, const char *file,
36                                                unsigned int line, const char *function,
37                                                const char *fmt, ...
[e59c088]38        ) __attribute__((noreturn, format(printf, 5, 6)));
39
40#endif
[12756de]41
[dafe9e1]42template<typename T, typename U>
[f685679]43static inline T strict_dynamic_cast( const U & src ) {
[8abee136]44        assert(src);
[4f147cc]45        T ret = dynamic_cast<T>(src);
[be151bf]46        assertf(ret, "%s", toString(src).c_str());
[4f147cc]47        return ret;
48}
49
[dafe9e1]50template<typename T, decltype(nullptr) null, typename U>
51static inline T strict_dynamic_cast( const U & src ) {
52        return src ? strict_dynamic_cast<T, U>( src ) : nullptr;
53}
54
[6a625de]55extern void abort(const char *fmt, ...  ) noexcept __attribute__((noreturn, format(printf, 1, 2)));
[12756de]56// Local Variables: //
57// tab-width: 4 //
58// mode: c++ //
59// compile-command: "make install" //
60// End: //
Note: See TracBrowser for help on using the repository browser.