xref: /aosp_15_r20/external/icu/libicu/cts_headers/uassert.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 2002-2011, International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *
11*0e209d39SAndroid Build Coastguard Worker * File uassert.h
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker *  Contains the U_ASSERT and UPRV_UNREACHABLE_* macros
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker #ifndef U_ASSERT_H
18*0e209d39SAndroid Build Coastguard Worker #define U_ASSERT_H
19*0e209d39SAndroid Build Coastguard Worker 
20*0e209d39SAndroid Build Coastguard Worker /* utypes.h is included to get the proper define for uint8_t */
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
22*0e209d39SAndroid Build Coastguard Worker /* for abort */
23*0e209d39SAndroid Build Coastguard Worker #include <stdlib.h>
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker /**
26*0e209d39SAndroid Build Coastguard Worker  * \def U_ASSERT
27*0e209d39SAndroid Build Coastguard Worker  * By default, U_ASSERT just wraps the C library assert macro.
28*0e209d39SAndroid Build Coastguard Worker  * By changing the definition here, the assert behavior for ICU can be changed
29*0e209d39SAndroid Build Coastguard Worker  * without affecting other non - ICU uses of the C library assert().
30*0e209d39SAndroid Build Coastguard Worker */
31*0e209d39SAndroid Build Coastguard Worker #if U_DEBUG
32*0e209d39SAndroid Build Coastguard Worker #   include <assert.h>
33*0e209d39SAndroid Build Coastguard Worker #   define U_ASSERT(exp) assert(exp)
34*0e209d39SAndroid Build Coastguard Worker #elif U_CPLUSPLUS_VERSION
35*0e209d39SAndroid Build Coastguard Worker #   define U_ASSERT(exp) (void)0
36*0e209d39SAndroid Build Coastguard Worker #else
37*0e209d39SAndroid Build Coastguard Worker #   define U_ASSERT(exp)
38*0e209d39SAndroid Build Coastguard Worker #endif
39*0e209d39SAndroid Build Coastguard Worker 
40*0e209d39SAndroid Build Coastguard Worker /**
41*0e209d39SAndroid Build Coastguard Worker  * \def UPRV_UNREACHABLE_ASSERT
42*0e209d39SAndroid Build Coastguard Worker  * This macro is used in places that we had believed were unreachable, but
43*0e209d39SAndroid Build Coastguard Worker  * experience has shown otherwise (possibly due to memory corruption, etc).
44*0e209d39SAndroid Build Coastguard Worker  * In this case we call assert() in debug versions as with U_ASSERT, instead
45*0e209d39SAndroid Build Coastguard Worker  * of unconditionally calling abort(). However we also allow redefinition as
46*0e209d39SAndroid Build Coastguard Worker  * with UPRV_UNREACHABLE_EXIT.
47*0e209d39SAndroid Build Coastguard Worker  * @internal
48*0e209d39SAndroid Build Coastguard Worker */
49*0e209d39SAndroid Build Coastguard Worker #if defined(UPRV_UNREACHABLE_ASSERT)
50*0e209d39SAndroid Build Coastguard Worker     // Use the predefined value.
51*0e209d39SAndroid Build Coastguard Worker #elif U_DEBUG
52*0e209d39SAndroid Build Coastguard Worker #   include <assert.h>
53*0e209d39SAndroid Build Coastguard Worker #   define UPRV_UNREACHABLE_ASSERT assert(false)
54*0e209d39SAndroid Build Coastguard Worker #elif U_CPLUSPLUS_VERSION
55*0e209d39SAndroid Build Coastguard Worker #   define UPRV_UNREACHABLE_ASSERT (void)0
56*0e209d39SAndroid Build Coastguard Worker #else
57*0e209d39SAndroid Build Coastguard Worker #   define UPRV_UNREACHABLE_ASSERT
58*0e209d39SAndroid Build Coastguard Worker #endif
59*0e209d39SAndroid Build Coastguard Worker 
60*0e209d39SAndroid Build Coastguard Worker /**
61*0e209d39SAndroid Build Coastguard Worker  * \def UPRV_UNREACHABLE_EXIT
62*0e209d39SAndroid Build Coastguard Worker  * This macro is used to unconditionally abort if unreachable code is ever executed.
63*0e209d39SAndroid Build Coastguard Worker  * @internal
64*0e209d39SAndroid Build Coastguard Worker */
65*0e209d39SAndroid Build Coastguard Worker #if defined(UPRV_UNREACHABLE_EXIT)
66*0e209d39SAndroid Build Coastguard Worker     // Use the predefined value.
67*0e209d39SAndroid Build Coastguard Worker #else
68*0e209d39SAndroid Build Coastguard Worker #   define UPRV_UNREACHABLE_EXIT abort()
69*0e209d39SAndroid Build Coastguard Worker #endif
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker #endif
72