Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_assert / public / pw_assert / light.h
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include "pw_assert/options.h"  // For PW_ASSERT_ENABLE_DEBUG
17 #include "pw_preprocessor/util.h"
18
19 PW_EXTERN_C_START
20
21 void pw_assert_HandleFailure(void);
22
23 PW_EXTERN_C_END
24
25 // A header- and constexpr-safe version of PW_CHECK().
26 //
27 // If the given condition is false, crash the system. Otherwise, do nothing.
28 // The condition is guaranteed to be evaluated. This assert implementation is
29 // guaranteed to be constexpr-safe.
30 //
31 // IMPORTANT: Unlike the PW_CHECK_*() suite of macros, this API captures no
32 // rich information like line numbers, the file, expression arguments, or the
33 // stringified expression. Use these macros only when absolutely necessary --
34 // in headers, constexr contexts, or in rare cases where the call site overhead
35 // of a full PW_CHECK must be avoided. Use PW_CHECK_*() whenever possible.
36 #define PW_ASSERT(condition)     \
37   do {                           \
38     if (!(condition)) {          \
39       pw_assert_HandleFailure(); \
40     }                            \
41   } while (0)
42
43 // A header- and constexpr-safe version of PW_DCHECK().
44 //
45 // Same as PW_ASSERT(), except that if PW_ASSERT_ENABLE_DEBUG == 1, the assert
46 // is disabled and condition is not evaluated.
47 //
48 // IMPORTANT: Unlike the PW_CHECK_*() suite of macros, this API captures no
49 // rich information like line numbers, the file, expression arguments, or the
50 // stringified expression. Use these macros only when absolutely necessary --
51 // in headers, constexr contexts, or in rare cases where the call site overhead
52 // of a full PW_CHECK must be avoided. Use PW_DCHECK_*() whenever possible.
53 #define PW_DASSERT(condition)                            \
54   do {                                                   \
55     if ((PW_ASSERT_ENABLE_DEBUG == 1) && !(condition)) { \
56       pw_assert_HandleFailure();                         \
57     }                                                    \
58   } while (0)