Embedded Template Library 1.0
Loading...
Searching...
No Matches
determine_compiler_language_support.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2019 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_DETERMINE_COMPILER_LANGUAGE_SUPPORT_H_INCLUDED
32#define ETL_DETERMINE_COMPILER_LANGUAGE_SUPPORT_H_INCLUDED
33
34// #include <math.h>
35
36#include "determine_compiler.h"
37
38// Determine C++26 support
39#if !defined(ETL_CPP26_SUPPORTED)
40 #if defined(__cplusplus)
41 #if defined(ETL_COMPILER_MICROSOFT)
42 #define ETL_CPP26_SUPPORTED (__cplusplus >= 202400L)
43 #elif defined(ETL_COMPILER_ARM5)
44 #define ETL_CPP26_SUPPORTED 0
45 #elif defined(ETL_COMPILER_GCC)
46 #define ETL_CPP26_SUPPORTED (__cplusplus >= 202400L)
47 #else
48 #define ETL_CPP26_SUPPORTED (__cplusplus >= 202400L)
49 #endif
50 #else
51 #define ETL_CPP26_SUPPORTED 0
52 #endif
53#endif
54
55#if ETL_CPP26_SUPPORTED
56 #define ETL_CPP11_SUPPORTED 1
57 #define ETL_CPP14_SUPPORTED 1
58 #define ETL_CPP17_SUPPORTED 1
59 #define ETL_CPP20_SUPPORTED 1
60 #define ETL_CPP23_SUPPORTED 1
61#endif
62
63// Determine C++23 support
64#if !defined(ETL_CPP23_SUPPORTED)
65 #if defined(__cplusplus)
66 #if defined(ETL_COMPILER_MICROSOFT)
67 #define ETL_CPP23_SUPPORTED (__cplusplus >= 202302L)
68 #elif defined(ETL_COMPILER_ARM5)
69 #define ETL_CPP23_SUPPORTED 0
70 #elif defined(ETL_COMPILER_GCC)
71 #define ETL_CPP23_SUPPORTED (__cplusplus >= 202302L)
72 #else
73 #define ETL_CPP23_SUPPORTED (__cplusplus >= 202302L)
74 #endif
75 #else
76 #define ETL_CPP23_SUPPORTED 0
77 #endif
78#endif
79
80#if ETL_CPP23_SUPPORTED
81 #define ETL_CPP11_SUPPORTED 1
82 #define ETL_CPP14_SUPPORTED 1
83 #define ETL_CPP17_SUPPORTED 1
84 #define ETL_CPP20_SUPPORTED 1
85#endif
86
87// Determine C++20 support
88#if !defined(ETL_CPP20_SUPPORTED)
89 #if defined(__cplusplus)
90 #if defined(ETL_COMPILER_MICROSOFT)
91 #if defined(_MSVC_LANG)
92 #define ETL_CPP20_SUPPORTED (_MSVC_LANG >= 202002L)
93 #else
94 #define ETL_CPP20_SUPPORTED (_MSC_VER >= 1929)
95 #endif
96 #elif defined(ETL_COMPILER_ARM5)
97 #define ETL_CPP20_SUPPORTED 0
98 #elif defined(ETL_COMPILER_GCC)
99 #if (__GNUC__ == 10)
100 #define ETL_CPP20_SUPPORTED (__cplusplus >= 201709L)
101 #else
102 #define ETL_CPP20_SUPPORTED (__cplusplus >= 202002L)
103 #endif
104 #else
105 #define ETL_CPP20_SUPPORTED (__cplusplus >= 202002L)
106 #endif
107 #else
108 #define ETL_CPP20_SUPPORTED 0
109 #endif
110#endif
111
112#if ETL_CPP20_SUPPORTED
113 #define ETL_CPP11_SUPPORTED 1
114 #define ETL_CPP14_SUPPORTED 1
115 #define ETL_CPP17_SUPPORTED 1
116#endif
117
118// Determine C++17 support
119#if !defined(ETL_CPP17_SUPPORTED)
120 #if defined(__cplusplus)
121 #if defined(ETL_COMPILER_MICROSOFT)
122 #if defined(_MSVC_LANG)
123 #define ETL_CPP17_SUPPORTED (_MSVC_LANG >= 201703L)
124 #else
125 #define ETL_CPP17_SUPPORTED (_MSC_VER >= 1914)
126 #endif
127 #elif defined(ETL_COMPILER_ARM5)
128 #define ETL_CPP17_SUPPORTED 0
129 #else
130 #define ETL_CPP17_SUPPORTED (__cplusplus >= 201703L)
131 #endif
132 #else
133 #define ETL_CPP17_SUPPORTED 0
134 #endif
135#endif
136
137#if ETL_CPP17_SUPPORTED
138 #define ETL_CPP11_SUPPORTED 1
139 #define ETL_CPP14_SUPPORTED 1
140#endif
141
142// Determine C++14 support
143#if !defined(ETL_CPP14_SUPPORTED)
144 #if defined(__cplusplus)
145 #if defined(ETL_COMPILER_MICROSOFT)
146 #if defined(_MSVC_LANG)
147 #define ETL_CPP14_SUPPORTED (_MSVC_LANG >= 201402L)
148 #else
149 #define ETL_CPP14_SUPPORTED (_MSC_VER >= 1900)
150 #endif
151 #elif defined(ETL_COMPILER_ARM5)
152 #define ETL_CPP14_SUPPORTED 0
153 #else
154 #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L)
155 #endif
156 #else
157 #define ETL_CPP14_SUPPORTED 0
158 #endif
159#endif
160
161#if ETL_CPP14_SUPPORTED
162 #define ETL_CPP11_SUPPORTED 1
163#endif
164
165// Determine C++11 support
166#if !defined(ETL_CPP11_SUPPORTED)
167 #if defined(__cplusplus)
168 #if defined(ETL_COMPILER_MICROSOFT)
169 #if defined(_MSVC_LANG)
170 #define ETL_CPP11_SUPPORTED (_MSVC_LANG >= 201103L)
171 #else
172 #define ETL_CPP11_SUPPORTED (_MSC_VER >= 1700)
173 #endif
174 #elif defined(ETL_COMPILER_ARM5)
175 #define ETL_CPP11_SUPPORTED 0
176 #else
177 #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L)
178 #endif
179 #else
180 #define ETL_CPP11_SUPPORTED 0
181 #endif
182#endif
183
184// Helper macros
185#define ETL_CPP11_NOT_SUPPORTED (!ETL_CPP11_SUPPORTED)
186#define ETL_CPP14_NOT_SUPPORTED (!ETL_CPP14_SUPPORTED)
187#define ETL_CPP17_NOT_SUPPORTED (!ETL_CPP17_SUPPORTED)
188#define ETL_CPP20_NOT_SUPPORTED (!ETL_CPP20_SUPPORTED)
189#define ETL_CPP23_NOT_SUPPORTED (!ETL_CPP23_SUPPORTED)
190#define ETL_CPP26_NOT_SUPPORTED (!ETL_CPP26_SUPPORTED)
191
192// 'Using' macros
193#define ETL_USING_CPP11 (ETL_CPP11_SUPPORTED == 1)
194#define ETL_USING_CPP14 (ETL_CPP14_SUPPORTED == 1)
195#define ETL_USING_CPP17 (ETL_CPP17_SUPPORTED == 1)
196#define ETL_USING_CPP20 (ETL_CPP20_SUPPORTED == 1)
197#define ETL_USING_CPP23 (ETL_CPP23_SUPPORTED == 1)
198#define ETL_USING_CPP26 (ETL_CPP26_SUPPORTED == 1)
199
200#define ETL_NOT_USING_CPP11 (ETL_CPP11_SUPPORTED == 0)
201#define ETL_NOT_USING_CPP14 (ETL_CPP14_SUPPORTED == 0)
202#define ETL_NOT_USING_CPP17 (ETL_CPP17_SUPPORTED == 0)
203#define ETL_NOT_USING_CPP20 (ETL_CPP20_SUPPORTED == 0)
204#define ETL_NOT_USING_CPP23 (ETL_CPP23_SUPPORTED == 0)
205#define ETL_NOT_USING_CPP26 (ETL_CPP26_SUPPORTED == 0)
206
207#if !defined(ETL_NO_NULLPTR_SUPPORT)
208 #define ETL_NO_NULLPTR_SUPPORT ETL_NOT_USING_CPP11
209#endif
210
211#if !defined(ETL_NO_SMALL_CHAR_SUPPORT)
212 #if ETL_USING_CPP20
213 #define ETL_NO_SMALL_CHAR_SUPPORT 0
214 #else
215 #define ETL_NO_SMALL_CHAR_SUPPORT 1
216 #endif
217#endif
218
219#if !defined(ETL_NO_LARGE_CHAR_SUPPORT)
220 #define ETL_NO_LARGE_CHAR_SUPPORT ETL_NOT_USING_CPP11
221#endif
222
223#if !defined(ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED)
224 #define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_USING_CPP11
225#endif
226
227// Language standard
228#if !defined(ETL_LANGUAGE_STANDARD)
229 #if ETL_USING_CPP26
230 #define ETL_LANGUAGE_STANDARD 26
231 #elif ETL_USING_CPP23
232 #define ETL_LANGUAGE_STANDARD 23
233 #elif ETL_USING_CPP20
234 #define ETL_LANGUAGE_STANDARD 20
235 #elif ETL_USING_CPP17
236 #define ETL_LANGUAGE_STANDARD 17
237 #elif ETL_USING_CPP14
238 #define ETL_LANGUAGE_STANDARD 14
239 #elif ETL_USING_CPP11
240 #define ETL_LANGUAGE_STANDARD 11
241 #else
242 #define ETL_LANGUAGE_STANDARD 3
243 #endif
244#endif
245
246// NAN not defined or Rowley CrossWorks
247#if !defined(ETL_NO_CPP_NAN_SUPPORT) && (!defined(NAN) || defined(__CROSSWORKS_ARM) || defined(ETL_COMPILER_ARM5) || defined(ARDUINO))
248 #define ETL_NO_CPP_NAN_SUPPORT
249#endif
250
251#if defined(__has_include)
252 #if __has_include(<version>)
253 #include <version>
254
255 #if defined(__cpp_lib_byteswap)
256 #if __cpp_lib_byteswap != 0
257 #define ETL_HAS_STD_BYTESWAP 1
258 #endif
259 #endif
260
261 #if defined(__cpp_lib_is_virtual_base_of)
262 #if __cpp_lib_is_virtual_base_of != 0
263 #define ETL_HAS_STD_IS_VIRTUAL_BASE_OF 1
264 #endif
265 #endif
266
267 #if defined(__cpp_lib_trivially_relocatable)
268 #if __cpp_lib_trivially_relocatable != 0
269 #define ETL_HAS_STD_TRIVIALLY_RELOCATABLE 1
270 #endif
271 #endif
272
273 #if defined(__cpp_lib_atomic_min_max)
274 #if __cpp_lib_atomic_min_max != 0
275 #define ETL_HAS_STD_ATOMIC_MIN_MAX 1
276 #endif
277 #endif
278 #endif
279#endif
280#ifndef ETL_HAS_STD_BYTESWAP
281 #define ETL_HAS_STD_BYTESWAP 0
282#endif
283#ifndef ETL_HAS_STD_IS_VIRTUAL_BASE_OF
284 #define ETL_HAS_STD_IS_VIRTUAL_BASE_OF 0
285#endif
286#ifndef ETL_HAS_STD_TRIVIALLY_RELOCATABLE
287 #define ETL_HAS_STD_TRIVIALLY_RELOCATABLE 0
288#endif
289#ifndef ETL_HAS_STD_ATOMIC_MIN_MAX
290 #define ETL_HAS_STD_ATOMIC_MIN_MAX 0
291#endif
292
293#endif