|
1 | | -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
2 | | -// |
3 | 1 | // compiler.h: Rcpp R/C++ interface class library -- check compiler |
4 | 2 | // |
5 | | -// Copyright (C) 2012 - 2013 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey |
| 3 | +// Copyright (C) 2012 - 2025 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey |
6 | 4 | // |
7 | 5 | // This file is part of Rcpp. |
8 | 6 | // |
|
43 | 41 | # error "This compiler is not supported" |
44 | 42 | #endif |
45 | 43 |
|
| 44 | +#if __cplusplus < 201103L |
| 45 | +# error "The C++ compilation standard is too old: use C++11 or newer." |
| 46 | +#endif |
| 47 | + |
46 | 48 | #ifdef __GNUC__ |
47 | 49 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) |
48 | | - // g++ 4.5 does not seem to like some of the fast indexing |
49 | | - #if GCC_VERSION >= 40500 |
50 | | - #define IS_GCC_450_OR_LATER |
51 | | - #endif |
52 | | - // g++ 4.6 switches from exception_defines.h to bits/exception_defines.h |
53 | | - #if GCC_VERSION < 40600 |
54 | | - #define IS_EARLIER_THAN_GCC_460 |
55 | | - #endif |
56 | | - #if GCC_VERSION >= 40600 |
57 | | - #define IS_GCC_460_OR_LATER |
58 | | - #endif |
59 | 50 | #endif |
60 | 51 |
|
61 | | -// Check for the presence of C++0x (or later) support |
62 | | -#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L) |
63 | | - #define RCPP_USING_CXX0X_OR_LATER |
64 | | -#endif |
| 52 | +// TODO: Clean in a subsequent round |
| 53 | +#define RCPP_USING_CXX0X_OR_LATER |
65 | 54 |
|
66 | | -// Check C++0x/11 features |
| 55 | +// Check C++11 features (could/should work generally) |
67 | 56 | #if defined(__INTEL_COMPILER) |
68 | | - #if __cplusplus >= 201103L |
69 | | - #define RCPP_USING_CXX11 |
70 | | - #if __INTEL_COMPILER >= 1210 |
71 | | - #define HAS_VARIADIC_TEMPLATES |
72 | | - #endif |
73 | | - #if __INTEL_COMPILER >= 1100 |
74 | | - #define HAS_STATIC_ASSERT |
75 | | - #endif |
| 57 | + #define RCPP_USING_CXX11 |
| 58 | + #if __INTEL_COMPILER >= 1210 |
| 59 | + #define HAS_VARIADIC_TEMPLATES |
| 60 | + #endif |
| 61 | + #if __INTEL_COMPILER >= 1100 |
| 62 | + #define HAS_STATIC_ASSERT |
76 | 63 | #endif |
77 | 64 | #elif defined(__clang__) |
78 | | - #if __cplusplus >= 201103L |
79 | | - #define RCPP_USING_CXX11 |
80 | | - #if __has_feature(cxx_variadic_templates) |
81 | | - #define HAS_VARIADIC_TEMPLATES |
82 | | - #endif |
83 | | - #if __has_feature(cxx_static_assert) |
84 | | - #define HAS_STATIC_ASSERT |
85 | | - #endif |
| 65 | + #define RCPP_USING_CXX11 |
| 66 | + #if __has_feature(cxx_variadic_templates) |
| 67 | + #define HAS_VARIADIC_TEMPLATES |
| 68 | + #endif |
| 69 | + #if __has_feature(cxx_static_assert) |
| 70 | + #define HAS_STATIC_ASSERT |
86 | 71 | #endif |
87 | 72 | #elif defined(__GNUC__) |
88 | | - #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
89 | | - #if GCC_VERSION >= 40300 |
90 | | - #define HAS_VARIADIC_TEMPLATES |
91 | | - #define HAS_STATIC_ASSERT |
92 | | - #endif |
| 73 | + #define RCPP_USING_CXX11 |
| 74 | + #if __has_feature(cxx_variadic_templates) |
| 75 | + #define HAS_VARIADIC_TEMPLATES |
| 76 | + #endif |
| 77 | + #if __has_feature(cxx_static_assert) |
| 78 | + #define HAS_STATIC_ASSERT |
93 | 79 | #endif |
94 | | - #if GCC_VERSION >= 40800 && __cplusplus >= 201103L |
95 | | - #define RCPP_USING_CXX11 |
96 | | - #endif |
97 | 80 | #endif |
98 | 81 |
|
99 | | -// Check C++0x headers |
| 82 | +// Check C++0x headers (TODO remove when no longer needed below) |
100 | 83 | #include <cmath> |
101 | 84 | #if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__)) |
102 | | - #if defined(__GLIBCXX__) && defined(__GXX_EXPERIMENTAL_CXX0X__) |
103 | | - #if GCC_VERSION >= 40400 |
104 | | - #define HAS_CXX0X_UNORDERED_MAP |
105 | | - #define HAS_CXX0X_UNORDERED_SET |
106 | | - #define HAS_CXX0X_INITIALIZER_LIST |
107 | | - #endif |
108 | | - #endif |
| 85 | + #define HAS_CXX0X_UNORDERED_MAP |
| 86 | + #define HAS_CXX0X_UNORDERED_SET |
| 87 | + #define HAS_CXX0X_INITIALIZER_LIST |
109 | 88 | #elif defined(__clang__) |
110 | | - #if __cplusplus >= 201103L |
111 | | - #if __has_include(<unordered_map>) |
112 | | - #define HAS_CXX0X_UNORDERED_MAP |
113 | | - #endif |
114 | | - #if __has_include(<unordered_set>) |
115 | | - #define HAS_CXX0X_UNORDERED_SET |
116 | | - #endif |
117 | | - #if __has_include(<initializer_list>) |
118 | | - #define HAS_CXX0X_INITIALIZER_LIST |
119 | | - #endif |
| 89 | + #if __has_include(<unordered_map>) |
| 90 | + #define HAS_CXX0X_UNORDERED_MAP |
| 91 | + #endif |
| 92 | + #if __has_include(<unordered_set>) |
| 93 | + #define HAS_CXX0X_UNORDERED_SET |
| 94 | + #endif |
| 95 | + #if __has_include(<initializer_list>) |
| 96 | + #define HAS_CXX0X_INITIALIZER_LIST |
120 | 97 | #endif |
121 | 98 | #endif |
122 | 99 |
|
123 | | -// Check TR1 Headers |
| 100 | +// Check TR1 Headers (TODO remove when no longer needed below) |
124 | 101 | #if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__)) |
125 | | - #if defined(__GLIBCXX__) |
126 | | - #if GCC_VERSION >= 40400 || ( GCC_VERSION >= 40201 && defined(__APPLE__) ) |
127 | | - #define HAS_TR1_UNORDERED_MAP |
128 | | - #define HAS_TR1_UNORDERED_SET |
129 | | - #endif |
130 | | - #endif |
| 102 | + #define HAS_TR1_UNORDERED_MAP |
| 103 | + #define HAS_TR1_UNORDERED_SET |
131 | 104 | #elif defined(__clang__) |
132 | | - #if __cplusplus >= 201103L |
133 | | - #if __has_include(<tr1/unordered_map>) |
134 | | - #define HAS_TR1_UNORDERED_MAP |
135 | | - #endif |
136 | | - #if __has_include(<tr1/unordered_set>) |
137 | | - #define HAS_TR1_UNORDERED_SET |
138 | | - #endif |
| 105 | + #if __has_include(<tr1/unordered_map>) |
| 106 | + #define HAS_TR1_UNORDERED_MAP |
| 107 | + #endif |
| 108 | + #if __has_include(<tr1/unordered_set>) |
| 109 | + #define HAS_TR1_UNORDERED_SET |
139 | 110 | #endif |
140 | 111 | #endif |
141 | 112 |
|
|
144 | 115 | #endif |
145 | 116 |
|
146 | 117 | // Conditionally include headers |
147 | | -#ifdef HAS_CXX0X_INITIALIZER_LIST |
| 118 | +// #ifdef HAS_CXX0X_INITIALIZER_LIST |
148 | 119 | #include <initializer_list> |
149 | | -#endif |
| 120 | +// #endif |
150 | 121 |
|
| 122 | +// TODO: Simplify further: First case should work generally |
151 | 123 | #ifdef RCPP_USING_CXX11 |
152 | 124 | #if defined(HAS_CXX0X_UNORDERED_MAP) |
153 | 125 | #include <unordered_map> |
|
0 commit comments