Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
diagnostics.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
///
6
/// @file diagnostics.hpp
7
/// @brief Provides macros used to disable and enable compiler specific diagnostics using the _Pragma operator
8
///
9
10
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_DIAGNOSTICS_HPP_
11
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_DIAGNOSTICS_HPP_
12
13
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
14
#
include
"arene/base/compiler_support/platform_queries.hpp"
15
#
include
"arene/base/compiler_support/preprocessor.hpp"
16
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
17
18
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
19
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Indirect call of _Pragma permitted by A16-0-1 Permit #1"
20
// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
21
22
/// @def ARENE_IGNORE_CLANG(s, comment)
23
/// @brief Pushes an ignore for a diagnostic into the compiler for @c clang only.
24
/// @param s The diagnostic to ignore
25
/// @param comment The justification for the diagnostic suppression. Is discarded in the compiled output.
26
/// @pre @c ARENE_IGNORE_START() has been called.
27
/// @pre The given diagnostic is a valid diagnostic for @c clang , else it will be a compiler error when evaluated by
28
/// @c clang.
29
/// @post The given diagnostic is suppressed when the active compiler is @c clang.
30
31
/// @def ARENE_IGNORE_ARMCLANG(s, comment)
32
/// @brief Pushes an ignore for a diagnostic into the compiler for @c armclang only.
33
/// @param s The diagnostic to ignore
34
/// @param comment The justification for the diagnostic suppression. Is discarded in the compiled output.
35
/// @pre @c ARENE_IGNORE_START() has been called.
36
/// @pre The given diagnostic is a valid diagnostic for @c armclang , else it will be a compiler error when evaluated by
37
/// @c armclang.
38
/// @post The given diagnostic is suppressed when the active compiler is @c armclang.
39
40
/// @def ARENE_IGNORE_GCC(s, comment)
41
/// @brief Pushes an ignore for a diagnostic into the compiler for @c gcc only (which includes @c qcc).
42
/// @param s The diagnostic to ignore
43
/// @param comment The justification for the diagnostic suppression. Is discarded in the compiled output.
44
/// @pre @c ARENE_IGNORE_START() has been called.
45
/// @pre The given diagnostic is a valid diagnostic for @c gcc, else it will be a compiler error when evaluated by
46
/// @c gcc.
47
/// @post The given diagnostic is suppressed when the active compiler is @c gcc.
48
49
/// @def ARENE_IGNORE_ALL(s, comment)
50
/// @brief Pushes an ignore for a diagnostic into the compiler for any compiler.
51
/// @param s The diagnostic to ignore
52
/// @param comment The justification for the diagnostic suppression. Is discarded in the compiled output.
53
/// @pre @c ARENE_IGNORE_START() has been called.
54
/// @pre The given diagnostic is a valid diagnostic for all compilers, else it may be a compiler error when evaluated by
55
/// an unsupported compiler.
56
/// @post The given diagnostic is suppressed.
57
58
/// @def ARENE_IGNORE_WSELFMOVE(comment)
59
/// @brief Pushes an ignore for the self-move diagnostic for applicable compilers.
60
/// @param comment The justification for suppressing the self-move diagnostic.
61
/// @pre @c ARENE_IGNORE_START() has been called.
62
/// @post The self-move diagnostic will not be issued.
63
64
// To extend support to a new compiler, one must:
65
// 1. Define ARENE_IGNORE_IMPL(s) for the compiler
66
// 2. Define ARENE_IGNORE_[COMPILER](s, comment) as ARENE_IGNORE_IMPL(s)
67
// 3. Define ARENE_IGNORE_ALL(s, comment) as ARENE_IGNORE_[COMPILER](s, (comment))
68
// 4. Define ARENE_IGNORE_W[DIAGNOSTIC](comment) as ARENE_IGNORE_[COMPILER]("-W[diagnostic]", (comment)) if applicable
69
// or a no-op otherwise.
70
// Supported diagnostics:
71
// - self-move
72
// 5. Define ARENE_IGNORE_[COMPILER](s, comment) as a no-op for all other compilers
73
// These defines must be placed within a block that is only evaluated for the respective compiler (i.e., the new
74
// compiler for steps 1-4, the existing compiler(s) for step 5).
75
76
#
if
ARENE_IS_ON
(
ARENE_COMPILER_ARMCLANG
)
77
#
define
ARENE_IGNORE_IMPL
(
s
)
_Pragma
(
ARENE_STRINGIZE
(
clang
diagnostic
s
)
)
ARENE_REQUIRE_SEMICOLON
78
#
define
ARENE_IGNORE_ARMCLANG
(
s
,
comment
)
ARENE_IGNORE_IMPL
(
ignored
s
)
79
// parasoft-begin-suppress AUTOSAR-M16_0_6-a-2 "'s' is a parameter to ## operator"
80
#
define
ARENE_IGNORE_ALL
(
s
,
comment
)
ARENE_IGNORE_ARMCLANG
(
s
,
(
comment
)
)
81
// parasoft-end-suppress AUTOSAR-M16_0_6-a-2
82
#
define
ARENE_IGNORE_WSELFMOVE
(
comment
)
ARENE_IGNORE_ARMCLANG
(
"-Wself-move"
,
(
comment
)
)
83
#
elif
ARENE_IS_ON
(
ARENE_COMPILER_CLANG
)
84
#
define
ARENE_IGNORE_IMPL
(
s
)
_Pragma
(
ARENE_STRINGIZE
(
clang
diagnostic
s
)
)
ARENE_REQUIRE_SEMICOLON
85
#
define
ARENE_IGNORE_CLANG
(
s
,
comment
)
ARENE_IGNORE_IMPL
(
ignored
s
)
86
// parasoft-begin-suppress AUTOSAR-M16_0_6-a-2 "'s' is a parameter to ## operator"
87
#
define
ARENE_IGNORE_ALL
(
s
,
comment
)
ARENE_IGNORE_CLANG
(
s
,
(
comment
)
)
88
// parasoft-end-suppress AUTOSAR-M16_0_6-a-2
89
#
define
ARENE_IGNORE_WSELFMOVE
(
comment
)
ARENE_IGNORE_CLANG
(
"-Wself-move"
,
(
comment
)
)
90
91
#
elif
ARENE_IS_ON
(
ARENE_COMPILER_GCC
)
92
#
define
ARENE_IGNORE_IMPL
(
s
)
_Pragma
(
ARENE_STRINGIZE
(
GCC
diagnostic
s
)
)
ARENE_REQUIRE_SEMICOLON
93
#
define
ARENE_IGNORE_GCC
(
s
,
comment
)
ARENE_IGNORE_IMPL
(
ignored
s
)
94
// parasoft-begin-suppress AUTOSAR-M16_0_6-a-2 "'s' is a parameter to ## operator"
95
#
define
ARENE_IGNORE_ALL
(
s
,
comment
)
ARENE_IGNORE_GCC
(
s
,
(
comment
)
)
96
// parasoft-end-suppress AUTOSAR-M16_0_6-a-2
97
#
if
__GNUC__
>=
13
98
#
define
ARENE_IGNORE_WSELFMOVE
(
comment
)
ARENE_IGNORE_GCC
(
"-Wself-move"
,
(
comment
)
)
99
#
else
// __GNUC__ < 13
100
#
define
ARENE_IGNORE_WSELFMOVE
(
comment
)
ARENE_REQUIRE_SEMICOLON
101
#
endif
102
103
#
else
104
/* to be extended for other compilers */
105
static_assert
(
false
,
"Unsupported compiler"
);
106
#
endif
// Active Compiler Macro Selection
107
108
// we must still define all the compiler-specific extension points for the not-selected compiler as no-ops so they are
109
// still valid macro calls
110
#
ifndef
ARENE_IGNORE_GCC
111
#
define
ARENE_IGNORE_GCC
(
s
,
comment
)
ARENE_REQUIRE_SEMICOLON
112
#
endif
// ARENE_IGNORE_GCC
113
#
ifndef
ARENE_IGNORE_CLANG
114
#
define
ARENE_IGNORE_CLANG
(
s
,
comment
)
ARENE_REQUIRE_SEMICOLON
115
#
endif
// ARENE_IGNORE_CLANG
116
#
ifndef
ARENE_IGNORE_ARMCLANG
117
#
define
ARENE_IGNORE_ARMCLANG
(
s
,
comment
)
ARENE_REQUIRE_SEMICOLON
118
#
endif
// ARENE_IGNORE_ARMCLANG
119
#
ifndef
ARENE_IGNORE_ALL
120
#
define
ARENE_IGNORE_ALL
(
s
,
comment
)
ARENE_REQUIRE_SEMICOLON
121
#
endif
// ARENE_IGNORE_ALL
122
123
/// @brief Begins a region of a suppressed diagnostic
124
/// @note There must be a call to @c ARENE_IGNORE_END() for each call to @c ARENE_IGNORE_START() .
125
#
define
ARENE_IGNORE_START
(
)
ARENE_IGNORE_IMPL
(
push
)
126
127
/// @brief Ends a region of a suppressed diagnostic
128
/// @pre There was a call to @c ARENE_IGNORE_START() and one of @c ARENE_IGNORE_CLANG , @c ARENE_IGNORE_GCC ,
129
/// or @c ARENE_IGNORE_ALL
130
#
define
ARENE_IGNORE_END
(
)
ARENE_IGNORE_IMPL
(
pop
)
131
132
// NOLINTEND(cppcoreguidelines-macro-usage)
133
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
134
// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
135
136
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_DIAGNOSTICS_HPP_
arene
base
compiler_support
diagnostics.hpp
Generated by
1.13.2