Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
has_builtin_is_constant_evaluated.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_IS_CONSTANT_EVALUATED_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_IS_CONSTANT_EVALUATED_HPP_
7
8// IWYU pragma: private, include "arene/base/compiler_support/platform_queries.hpp"
9// IWYU pragma: friend "arene/base/compiler_support/platform_queries/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12#include "arene/base/compiler_support/platform_queries/compiler_info.hpp" // IWYU pragma: keep
13#include "arene/base/compiler_support/platform_queries/has_builtin.hpp"
14#include "arene/base/compiler_support/preprocessor.hpp"
15// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
16
17// NOLINTBEGIN(cppcoreguidelines-macro-usage) Explicitly providing compiler support macro functions
18// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Conditional defines permitted by A16-0-1 Permit #2"
19// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
20
21/// @def ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED
22/// @brief A platform support query for testing if @c __builtin_is_constant_evaluated is defined.
23///
24/// Usage:
25/// @code{c++}
26/// #if ARENE_IS_ON(ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED)
27/// @endcode
28///
29/// The value of this query is determined as follows, in order of precedence:
30/// 1. If @c __builtin_is_constant_evaluated is defined, it is @c ARENE_ON_BY_DEFAULT
31/// 1. Otherwise, it is @c ARENE_OFF_BY_DEFAULT
32
33// parasoft-begin-suppress AUTOSAR-M16_0_7-a-2 "False positive: not used as a macro"
34#if ARENE_HAS_BUILTIN(__builtin_is_constant_evaluated)
35// parasoft-end-suppress AUTOSAR-M16_0_7-a-2
36#define ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED_I_ ARENE_ON_BY_DEFAULT
37#elif ARENE_IS_ON(ARENE_COMPILER_GCC) && __GNUC__ == 9
38// The __builtin_is_constant_evaluated() intrinsic was added in GCC 9
39// but the __has_builtin query was not added until GCC 10 and so we
40// may have returned a false negative when probing for the builtin above.
41#define ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED_I_ ARENE_ON_BY_DEFAULT
42#else
43#define ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED_I_ ARENE_OFF_BY_DEFAULT
44#endif
45
46#ifdef ARENE_DOC_GENERATION_RUNNING // make this appear when running doxygen, as it won't otherwise.
47#ifndef ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED
48#define ARENE_HAS_BUILTIN_IS_CONSTANT_EVALUATED
49#endif
50#endif
51
52// NOLINTEND(cppcoreguidelines-macro-usage) Explicitly providing compiler support macro functions
53// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
54// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
55
56#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_IS_CONSTANT_EVALUATED_HPP_