Debian Codegraph @

include/ruby/internal/has/c_attribute.h

raw
1 #ifndef RBIMPL_HAS_C_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_HAS_C_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_C_ATTRIBUTE.
22 */
23
24 #include "ruby/internal/has/extension.h"
25 #include "ruby/internal/has/warning.h"
26
27 /** Wraps (or simulates) `__has_c_attribute`. */
28 #if defined(__cplusplus)
29 # /* Makes no sense. */
30 # define RBIMPL_HAS_C_ATTRIBUTE(_) 0
31
32 #elif RBIMPL_HAS_EXTENSION(c_attributes)
33 # /* Hmm. It seems Clang 17 has this macro defined even when -std=c99 mode,
34 # * _and_ fails to compile complaining that attributes are C2X feature. We
35 # * need to work around this nonsense. */
36 # define RBIMPL_HAS_C_ATTRIBUTE(_) __has_c_attribute(_)
37
38 #elif RBIMPL_HAS_WARNING("-Wc2x-extensions")
39 # define RBIMPL_HAS_C_ATTRIBUTE(_) 0
40
41 #elif defined(__has_c_attribute)
42 # define RBIMPL_HAS_C_ATTRIBUTE(_) __has_c_attribute(_)
43
44 #else
45 # /* As of writing everything that lacks __has_c_attribute also completely
46 # * lacks C2x attributes as well. Might change in future? */
47 # define RBIMPL_HAS_C_ATTRIBUTE(_) 0
48 #endif
49
50 #endif /* RBIMPL_HAS_C_ATTRIBUTE_H */