1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 #include "pw_assert/options.h" // For PW_ASSERT_ENABLE_DEBUG
17 #include "pw_preprocessor/util.h"
21 void pw_assert_HandleFailure(void);
25 // A header- and constexpr-safe version of PW_CHECK().
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.
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) \
39 pw_assert_HandleFailure(); \
43 // A header- and constexpr-safe version of PW_DCHECK().
45 // Same as PW_ASSERT(), except that if PW_ASSERT_ENABLE_DEBUG == 1, the assert
46 // is disabled and condition is not evaluated.
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) \
55 if ((PW_ASSERT_ENABLE_DEBUG == 1) && !(condition)) { \
56 pw_assert_HandleFailure(); \