Debian Codegraph @

include/ruby/internal/has/cpp_attribute.h

raw
1 #ifndef RBIMPL_HAS_CPP_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_HAS_CPP_ATTRIBUTE_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Defines #RBIMPL_HAS_CPP_ATTRIBUTE.
22 */
23 #include "ruby/internal/compiler_is.h"
24 #include "ruby/internal/compiler_since.h"
25
26 /** @cond INTERNAL_MACRO */
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
74 /** @endcond */
75
76 /** Wraps (or simulates) `__has_cpp_attribute`. */
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 */