1 // Copyright (c) 2013 Antoine Tran Tan 2 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. 3 // Copyright (c) 2007 Peter Dimov 4 // Copyright (c) Beman Dawes 2011 5 // 6 // Distributed under the Boost Software License, Version 1.0. (See accompanying 7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 9 // Make HPX inspect tool happy: hpxinspect:noassert_macro 10 // hpxinspect:noinclude:HPX_ASSERT 11 // hpxinspect:nodeprecatedname:BOOST_ASSERT 12 13 // Note: There are no include guards. This is intentional. 14 15 #if defined(HPX_USE_BOOST_ASSERT) 16 # include <boost/assert.hpp> 17 # define HPX_ASSERT(expr) BOOST_ASSERT(expr) 18 # define HPX_ASSERT_MSG(expr, msg) BOOST_ASSERT_MSG(expr, msg) 19 #else 20 21 #include <hpx/config.hpp> 22 23 //-------------------------------------------------------------------------- // 24 // HPX_ASSERT // 25 //-------------------------------------------------------------------------- // 26 27 #undef HPX_ASSERT 28 29 #if defined(__CUDA_ARCH__) 30 #define HPX_ASSERT(expr) ((void)0) 31 #else 32 33 #if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) 34 35 #if defined(HPX_GCC_VERSION) || defined(HPX_CLANG_VERSION) 36 # define HPX_ASSERT(expr) ((expr) ? (void)0 : __builtin_unreachable()) 37 #elif defined(HPX_MSVC) && !defined(HPX_INTEL_WIN) 38 # define HPX_ASSERT(expr) __assume(!!(expr)) 39 #else 40 # define HPX_ASSERT(expr) ((void)0) 41 #endif 42 43 #elif defined(HPX_ENABLE_ASSERT_HANDLER) || defined(BOOST_ENABLE_ASSERT_HANDLER) 44 45 #include <hpx/config.hpp> 46 #include <boost/current_function.hpp> 47 48 namespace hpx 49 { 50 HPX_NORETURN HPX_EXPORT void assertion_failed(char const * expr, 51 char const * function, char const * file, long line); // user defined 52 } // namespace hpx 53 54 #define HPX_ASSERT(expr) (HPX_LIKELY(!!(expr)) \ 55 ? ((void)0) \ 56 : ::hpx::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 57 58 #else 59 # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same 60 # define HPX_ASSERT(expr) assert(expr) 61 #endif 62 #endif 63 64 //-------------------------------------------------------------------------- // 65 // HPX_ASSERT_MSG // 66 //-------------------------------------------------------------------------- // 67 68 # undef HPX_ASSERT_MSG 69 70 #if defined(__CUDA_ARCH__) 71 #define HPX_ASSERT_MSG(expr) ((void)0) 72 #else 73 74 #if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) 75 76 #if defined(HPX_GCC_VERSION) || defined(HPX_CLANG_VERSION) 77 # define HPX_ASSERT_MSG(expr, msg) ((expr) ? (void)0 : __builtin_unreachable()) 78 #elif defined(HPX_MSVC) && !defined(HPX_INTEL_WIN) 79 # define HPX_ASSERT_MSG(expr, msg) __assume(!!(expr)) 80 #else 81 # define HPX_ASSERT_MSG(expr, msg) ((void)0) 82 #endif 83 84 #elif defined(HPX_ENABLE_ASSERT_HANDLER) || defined(BOOST_ENABLE_ASSERT_HANDLER) 85 86 #include <hpx/config.hpp> 87 #include <boost/current_function.hpp> 88 89 namespace hpx 90 { 91 HPX_NORETURN HPX_EXPORT void assertion_failed_msg( 92 char const * expr, char const * msg, 93 char const * function, char const * file, long line); // user defined 94 } // namespace hpx 95 96 #define HPX_ASSERT_MSG(expr, msg) (HPX_LIKELY(!!(expr)) \ 97 ? ((void)0) \ 98 : ::hpx::assertion_failed_msg \ 99 (#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 100 101 #else 102 103 #ifndef HPX_ASSERT_HPP 104 #define HPX_ASSERT_HPP 105 106 #include <hpx/config.hpp> 107 #include <boost/current_function.hpp> 108 #include <cstdlib> 109 #include <iostream> 110 111 // IDE's like Visual Studio perform better if output goes to std::cout or 112 // some other stream, so allow user to configure output stream: 113 #ifndef HPX_ASSERT_MSG_OSTREAM 114 # define HPX_ASSERT_MSG_OSTREAM std::cerr 115 #endif 116 117 namespace hpx { namespace assertion { namespace detail 118 { 119 // Note: The template is needed to make the function non-inline and 120 // avoid linking errors 121 template <typename CharT> assertion_failed_msg(CharT const * expr,char const * msg,char const * function,char const * file,long line)122 HPX_NORETURN HPX_NOINLINE void assertion_failed_msg( 123 CharT const * expr, char const * msg, char const * function, 124 char const * file, long line) 125 { 126 HPX_ASSERT_MSG_OSTREAM 127 << "***** Internal Program Error - assertion (" << expr 128 << ") failed in " << function << ":\n" 129 << file << '(' << line << "): " << msg << std::endl; 130 #ifdef UNDER_CE 131 // The Windows CE CRT library does not have abort() so use exit(-1) instead. 132 std::exit(-1); 133 #else 134 std::abort(); 135 #endif 136 } 137 }}} 138 139 #endif 140 141 #define HPX_ASSERT_MSG(expr, msg) (HPX_LIKELY(!!(expr)) \ 142 ? ((void)0) \ 143 : ::hpx::assertion::detail::assertion_failed_msg(#expr, msg, \ 144 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 145 #endif 146 #endif 147 148 //---------------------------------------------------------------------------// 149 // HPX_VERIFY // 150 //---------------------------------------------------------------------------// 151 152 #undef HPX_VERIFY 153 154 #if defined(HPX_DISABLE_ASSERTS) || ( !defined(HPX_ENABLE_ASSERT_HANDLER) \ 155 && defined(NDEBUG) ) || defined(BOOST_DISABLE_ASSERTS) \ 156 || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) 157 158 # define HPX_VERIFY(expr) ((void)(expr)) 159 160 #else 161 162 # define HPX_VERIFY(expr) HPX_ASSERT(expr) 163 164 #endif 165 166 #endif 167