Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
has_attribute.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_ATTRIBUTES_HAS_ATTRIBUTE_HPP_
6
#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_ATTRIBUTES_HAS_ATTRIBUTE_HPP_
7
8
// IWYU pragma: private, include "arene/base/compiler_support/attributes.hpp"
9
// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11
// NOLINTBEGIN(cppcoreguidelines-macro-usage) Explicitly providing compiler support macro functions
12
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Conditional defines permitted by A16-0-1 Permit #2"
13
// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
14
15
/// @def ARENE_HAS_STD_ATTRIBUTE
16
/// @brief A wrapper around the "standard" @c __has_cpp_attribute or @c __has_c_attribute query.
17
/// @param ... The attribute to query for.
18
/// @return if @c __has_c[pp]_attribute is defined, the result of @c __has_c[pp]_attribute(__VA_ARGS__) , otherwise @c
19
/// false .
20
21
// We only ever compile a single file in C or C++ mode; never both
22
// therefore, we want has attribute to map to the current standard
23
// "has attribute"
24
#if defined(__has_cpp_attribute)
25
#define ARENE_HAS_STD_ATTRIBUTE(...) __has_cpp_attribute(__VA_ARGS__)
26
#elif defined(__has_c_attribute)
27
#define ARENE_HAS_STD_ATTRIBUTE(...) __has_c_attribute(__VA_ARGS__)
28
#else
29
#define ARENE_HAS_STD_ATTRIBUTE(...) 0
30
#endif
// checking for standard __has_(c|cpp)_attribute
31
32
/// @def ARENE_HAS_OLD_ATTRIBUTE
33
/// @brief A wrapper around the "old style" @c __has_attribute query.
34
/// @param ... The attribute to query for.
35
/// @return if @c __has_attribute is defined, the result of @c __has_attribute(__VA_ARGS__) , otherwise @c false .
36
/// @note Users should generally prefer @c ARENE_HAS_STD_ATTRIBUTE or @c ARENE_HAS_ATTRIBUTE .
37
38
#if defined(__has_attribute)
39
#define ARENE_HAS_OLD_ATTRIBUTE(...) __has_attribute(__VA_ARGS__)
40
#else
41
#define ARENE_HAS_OLD_ATTRIBUTE(...) 0
42
#endif
// checking for old-style __has_attribute
43
44
/// @def ARENE_HAS_ATTRIBUTE
45
/// @brief A wrapper for testing for an attribute which will fall back to the "old" style query if the "standard" one is
46
/// not available.
47
/// @param ... The attribute to query for.
48
/// @return The result of invoking @c ARENE_HAS_STD_ATTRIBUTE if possible, else @c ARENE_HAS_OLD_ATTRIBUTE .
49
/// @note Users should generally prefer @c ARENE_HAS_STD_ATTRIBUTE . Only use this if you know you need to.
50
#if defined(__has_cpp_attribute)
51
#define ARENE_HAS_ATTRIBUTE(...) ARENE_HAS_STD_ATTRIBUTE(__VA_ARGS__)
52
#elif defined(__has_c_attribute)
53
#define ARENE_HAS_ATTRIBUTE(...) ARENE_HAS_STD_ATTRIBUTE(__VA_ARGS__)
54
#else
55
#define ARENE_HAS_ATTRIBUTE(...) ARENE_HAS_OLD_ATTRIBUTE(__VA_ARGS__)
56
#endif
// checking for any attribute in any form
57
58
// NOLINTEND(cppcoreguidelines-macro-usage) Explicitly providing compiler support macro functions
59
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
60
// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
61
62
#endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_ATTRIBUTES_HAS_ATTRIBUTE_HPP_
arene
base
compiler_support
attributes
has_attribute.hpp
Generated by
1.13.2