xref: /oneTBB/include/oneapi/tbb/detail/_assert.h (revision 68e075cb)
1 /*
2     Copyright (c) 2005-2021 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef __TBB_detail__assert_H
18 #define __TBB_detail__assert_H
19 
20 #include "_config.h"
21 
22 namespace tbb {
23 namespace detail {
24 namespace r1 {
25 //! Process an assertion failure.
26 /** Normally called from __TBB_ASSERT macro.
27   If assertion handler is null, print message for assertion failure and abort.
28   Otherwise call the assertion handler. */
29 void __TBB_EXPORTED_FUNC assertion_failure(const char* location, int line, const char* expression, const char* comment);
30 } // namespace r1
31 } // namespace detail
32 } // namespace tbb
33 
34 //! Release version of assertions
35 #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : tbb::detail::r1::assertion_failure(__func__,__LINE__,#predicate,message))
36 
37 #if TBB_USE_ASSERT
38     //! Assert that predicate is true.
39     /** If predicate is false, print assertion failure message.
40         If the comment argument is not NULL, it is printed as part of the failure message.
41         The comment argument has no other effect. */
42     #define __TBB_ASSERT(predicate,message) __TBB_ASSERT_RELEASE(predicate,message)
43     //! "Extended" version
44     #define __TBB_ASSERT_EX __TBB_ASSERT
45 #else
46     //! No-op version of __TBB_ASSERT.
47     #define __TBB_ASSERT(predicate,comment) ((void)0)
48     //! "Extended" version is useful to suppress warnings if a variable is only used with an assert
49     #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
50 #endif // TBB_USE_ASSERT
51 
52 #endif // __TBB_detail__assert_H
53