• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/config.h"  // For PW_ASSERT_ENABLE_DEBUG
17 #include "pw_assert_backend/assert_lite_backend.h"
18 
19 // A header- and constexpr-safe version of PW_CHECK().
20 //
21 // If the given condition is false, crash the system. Otherwise, do nothing.
22 // The condition is guaranteed to be evaluated. This assert implementation is
23 // guaranteed to be constexpr-safe.
24 //
25 // IMPORTANT: Unlike the PW_CHECK_*() suite of macros, this API captures no
26 // rich information like line numbers, the file, expression arguments, or the
27 // stringified expression. Use these macros only when absolutely necessary --
28 // in headers, constexr contexts, or in rare cases where the call site overhead
29 // of a full PW_CHECK must be avoided. Use PW_CHECK_*() whenever possible.
30 #define PW_ASSERT(condition)                \
31   do {                                      \
32     if (!(condition)) {                     \
33       PW_ASSERT_HANDLE_FAILURE(#condition); \
34     }                                       \
35   } while (0)
36 
37 // A header- and constexpr-safe version of PW_DCHECK().
38 //
39 // Same as PW_ASSERT(), except that if PW_ASSERT_ENABLE_DEBUG == 1, the assert
40 // is disabled and condition is not evaluated.
41 //
42 // IMPORTANT: Unlike the PW_CHECK_*() suite of macros, this API captures no
43 // rich information like line numbers, the file, expression arguments, or the
44 // stringified expression. Use these macros only when absolutely necessary --
45 // in headers, constexr contexts, or in rare cases where the call site overhead
46 // of a full PW_CHECK must be avoided. Use PW_DCHECK_*() whenever possible.
47 #define PW_DASSERT(condition)                            \
48   do {                                                   \
49     if ((PW_ASSERT_ENABLE_DEBUG == 1) && !(condition)) { \
50       PW_ASSERT_HANDLE_FAILURE(#condition);              \
51     }                                                    \
52   } while (0)
53