Ruby: include/ruby/internal/has/cpp_attribute.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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