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