Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_assert_basic / public / pw_assert_basic / assert_basic.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_basic/handler.h"
17 #include "pw_preprocessor/compiler.h"
18 #include "pw_preprocessor/util.h"
19
20 // Die with a message with many attributes included. This is the crash macro
21 // frontend that funnels everything into the C handler provided by the user,
22 // pw_assert_basic_HandleFailure().
23 #define PW_HANDLE_CRASH(...)     \
24   pw_assert_basic_HandleFailure( \
25       __FILE__, __LINE__, __func__ PW_COMMA_ARGS(__VA_ARGS__))
26
27 // Die with a message with many attributes included. This is the crash macro
28 // frontend that funnels everything into the C handler provided by the user,
29 // pw_assert_basic_HandleFailure().
30 #define PW_HANDLE_ASSERT_FAILURE(condition_string, message, ...)  \
31   pw_assert_basic_HandleFailure(__FILE__,                         \
32                                 __LINE__,                         \
33                                 __func__,                         \
34                                 "Check failed: " condition_string \
35                                 ". " message PW_COMMA_ARGS(__VA_ARGS__))
36
37 // Sample assert failure message produced by the below implementation:
38 //
39 //   Check failed: current_sensor (=610) < new_sensor (=50). More details!
40 //
41 // Putting the value next to the operand makes the string easier to read.
42
43 // clang-format off
44 // This is too hairy for clang format to handle and retain readability.
45 #define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str,         \
46                                                 arg_a_val,         \
47                                                 comparison_op_str, \
48                                                 arg_b_str,         \
49                                                 arg_b_val,         \
50                                                 type_fmt,          \
51                                                 message, ...)      \
52   pw_assert_basic_HandleFailure(                                   \
53            __FILE__,                                               \
54            __LINE__,                                               \
55            __func__,                                               \
56            "Check failed: "                                        \
57                arg_a_str " (=" type_fmt ") "                       \
58                comparison_op_str " "                               \
59                arg_b_str " (=" type_fmt ")"                        \
60                ". " message,                                       \
61             arg_a_val, arg_b_val PW_COMMA_ARGS(__VA_ARGS__))
62 // clang-format on