Ruby  3.4.0dev (2024-11-05 revision e440268d51fe02b303e3817a7a733a0dac1c5091)
cpp_attribute.h
Go to the documentation of this file.
1 #ifndef RBIMPL_HAS_CPP_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_HAS_CPP_ATTRIBUTE_H
25 
27 #if RBIMPL_COMPILER_IS(SunPro)
28 # /* Oracle Developer Studio 12.5's C++ preprocessor is reportedly broken. We
29 # * could simulate __has_cpp_attribute like below, but don't know the exact
30 # * list of which version supported which attribute. Just kill everything for
31 # * now. If you can please :FIXME: */
32 # /* https://unicode-org.atlassian.net/browse/ICU-12893 */
33 # /* https://github.com/boostorg/config/pull/95 */
34 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0
35 
36 #elif defined(__has_cpp_attribute)
37 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) __has_cpp_attribute(_)
38 
39 #elif RBIMPL_COMPILER_IS(MSVC)
40 # /* MSVC has never updated its __cplusplus since forever (unless specified
41 # * explicitly by a compiler flag). They also lack __has_cpp_attribute until
42 # * 2019. However, they do have attributes since 2015 or so. */
43 # /* https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance */
44 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
45 # define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
46 # define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
47 # define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
48 # define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
49 # define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
50 # define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
51 
52 #elif RBIMPL_COMPILER_BEFORE(Clang, 3, 6, 0)
53 # /* Clang 3.6.0 introduced __has_cpp_attribute. Prior to that following
54 # * attributes were already there. */
55 # /* https://clang.llvm.org/cxx_status.html */
56 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
57 # define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(Clang, 3, 3, 0)
58 # define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(Clang, 3, 4, 0)
59 
60 #elif RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0)
61 # /* GCC 5+ have __has_cpp_attribute, while 4.x had following attributes. */
62 # /* https://gcc.gnu.org/projects/cxx-status.html */
63 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
64 # define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
65 # define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
66 
67 #else
68 # /* :FIXME:
69 # * Candidate compilers to list here:
70 # * - icpc: They have __INTEL_CXX11_MODE__.
71 # */
72 # define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0
73 #endif
77 #if ! defined(__cplusplus)
78 # /* Makes no sense. */
79 # define RBIMPL_HAS_CPP_ATTRIBUTE(_) 0
80 #else
81 # /* GCC needs workarounds. See https://gcc.godbolt.org/z/jdz3pa */
82 # define RBIMPL_HAS_CPP_ATTRIBUTE(_) \
83  ((RBIMPL_HAS_CPP_ATTRIBUTE0(_) <= __cplusplus) ? RBIMPL_HAS_CPP_ATTRIBUTE0(_) : 0)
84 #endif
85 
86 #endif /* RBIMPL_HAS_CPP_ATTRIBUTE_H */
Defines RBIMPL_COMPILER_IS.
Defines RBIMPL_COMPILER_SINCE.