| 1 |
#ifndef RBIMPL_ATTR_CONSTEXPR_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_ATTR_CONSTEXPR_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 #RBIMPL_ATTR_CONSTEXPR. |
| 22 |
*/ |
| 23 |
#include "ruby/internal/has/feature.h" |
| 24 |
#include "ruby/internal/compiler_is.h" |
| 25 |
|
| 26 |
/** @cond INTERNAL_MACRO */ |
| 27 |
#if ! defined(__cplusplus) |
| 28 |
# /* Makes no sense. */ |
| 29 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 |
| 30 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 |
| 31 |
|
| 32 |
#elif defined(__cpp_constexpr) |
| 33 |
# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ |
| 34 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L) |
| 35 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L) |
| 36 |
|
| 37 |
#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0) |
| 38 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00) |
| 39 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00) |
| 40 |
|
| 41 |
#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0) |
| 42 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) |
| 43 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) |
| 44 |
|
| 45 |
#elif RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) |
| 46 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) |
| 47 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) |
| 48 |
|
| 49 |
#elif RBIMPL_HAS_FEATURE(cxx_relaxed_constexpr) |
| 50 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 |
| 51 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1 |
| 52 |
|
| 53 |
#elif RBIMPL_HAS_FEATURE(cxx_constexpr) |
| 54 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 |
| 55 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 |
| 56 |
|
| 57 |
#else |
| 58 |
# /* :FIXME: icpc must have constexpr but don't know how to detect. */ |
| 59 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 |
| 60 |
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 |
| 61 |
#endif |
| 62 |
/** @endcond */ |
| 63 |
|
| 64 |
/** Wraps (or simulates) C++11 `constexpr`. */ |
| 65 |
#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 |
| 66 |
# define RBIMPL_ATTR_CONSTEXPR(_) constexpr |
| 67 |
|
| 68 |
#elif RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 |
| 69 |
# define RBIMPL_ATTR_CONSTEXPR(_) RBIMPL_ATTR_CONSTEXPR_ ## _ |
| 70 |
# define RBIMPL_ATTR_CONSTEXPR_CXX11 constexpr |
| 71 |
# define RBIMPL_ATTR_CONSTEXPR_CXX14 /* void */ |
| 72 |
|
| 73 |
#else |
| 74 |
# define RBIMPL_ATTR_CONSTEXPR(_) /* void */ |
| 75 |
#endif |
| 76 |
|
| 77 |
/** Enables #RBIMPL_ATTR_CONSTEXPR if and only if. ! #RUBY_DEBUG. */ |
| 78 |
#if !RUBY_DEBUG |
| 79 |
# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) RBIMPL_ATTR_CONSTEXPR(_) |
| 80 |
#else |
| 81 |
# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) /* void */ |
| 82 |
#endif |
| 83 |
|
| 84 |
#endif /* RBIMPL_ATTR_CONSTEXPR_H */ |