Ruby: include/ruby/internal/static_assert.h Source File

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

static_assert.h
Go to the documentation of this file.
1#ifndef RBIMPL_STATIC_ASSERT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_STATIC_ASSERT_H
23#include <assert.h>
24#include "ruby/internal/has/extension.h"
25#include "ruby/internal/compiler_since.h"
26#include "ruby/internal/attr/maybe_unused.h"
27
29#if defined(__cplusplus) && defined(__cpp_static_assert)
30# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */
31# define RBIMPL_STATIC_ASSERT0 static_assert
32
33#elif defined(__cplusplus) && RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0)
34# define RBIMPL_STATIC_ASSERT0 static_assert
35
36#elif defined(__INTEL_CXX11_MODE__)
37# define RBIMPL_STATIC_ASSERT0 static_assert
38
39#elif defined(__cplusplus) && __cplusplus >= 201103L
40# define RBIMPL_STATIC_ASSERT0 static_assert
41
42#elif defined(__cplusplus) && RBIMPL_HAS_EXTENSION(cxx_static_assert)
43# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert
44
45#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__
46# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert
47
48#elif defined(__STDC_VERSION__) && RBIMPL_HAS_EXTENSION(c_static_assert)
49# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert
50
51#elif defined(__STDC_VERSION__) && RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0)
52# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert
53
54#elif defined(static_assert)
55# /* Take <assert.h> definition */
56# define RBIMPL_STATIC_ASSERT0 static_assert
57#endif
66#if defined(__DOXYGEN__)
67# define RBIMPL_STATIC_ASSERT static_assert
68
69#elif defined(RBIMPL_STATIC_ASSERT0)
70# define RBIMPL_STATIC_ASSERT(name, expr) \
71 RBIMPL_STATIC_ASSERT0(expr, # name ": " # expr)
72
73#else
74# define RBIMPL_STATIC_ASSERT(name, expr) \
75 RBIMPL_ATTR_MAYBE_UNUSED() typedef int static_assert_ ## name ## _check[1 - 2 * !(expr)]
76#endif
77
78#endif /* RBIMPL_STATIC_ASSERT_H */
assert.h
compiler_since.h
Defines RBIMPL_COMPILER_SINCE.
extension.h
Defines RBIMPL_HAS_EXTENSION.
maybe_unused.h
Defines RBIMPL_ATTR_MAYBE_UNUSED.