1 //
2 // Copyright 2017 The Abseil Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      https://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // -----------------------------------------------------------------------------
17 // File: config.h
18 // -----------------------------------------------------------------------------
19 //
20 // This header file defines a set of macros for checking the presence of
21 // important compiler and platform features. Such macros can be used to
22 // produce portable code by parameterizing compilation based on the presence or
23 // lack of a given feature.
24 //
25 // We define a "feature" as some interface we wish to program to: for example,
26 // a library function or system call. A value of `1` indicates support for
27 // that feature; any other value indicates the feature support is undefined.
28 //
29 // Example:
30 //
31 // Suppose a programmer wants to write a program that uses the 'mmap()' system
32 // call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
33 // selectively include the `mmap.h` header and bracket code using that feature
34 // in the macro:
35 //
36 //   #include "absl/base/config.h"
37 //
38 //   #ifdef ABSL_HAVE_MMAP
39 //   #include "sys/mman.h"
40 //   #endif  //ABSL_HAVE_MMAP
41 //
42 //   ...
43 //   #ifdef ABSL_HAVE_MMAP
44 //   void *ptr = mmap(...);
45 //   ...
46 //   #endif  // ABSL_HAVE_MMAP
47 
48 #ifndef ABSL_BASE_CONFIG_H_
49 #define ABSL_BASE_CONFIG_H_
50 
51 // Included for the __GLIBC__ macro (or similar macros on other systems).
52 #include <limits.h>
53 
54 #ifdef __cplusplus
55 // Included for __GLIBCXX__, _LIBCPP_VERSION
56 #include <cstddef>
57 #endif  // __cplusplus
58 
59 #if defined(__APPLE__)
60 // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
61 // __IPHONE_8_0.
62 #include <Availability.h>
63 #include <TargetConditionals.h>
64 #endif
65 
66 #include "absl/base/options.h"
67 #include "absl/base/policy_checks.h"
68 
69 // Helper macro to convert a CPP variable to a string literal.
70 #define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
71 #define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x)
72 
73 // -----------------------------------------------------------------------------
74 // Abseil namespace annotations
75 // -----------------------------------------------------------------------------
76 
77 // ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END
78 //
79 // An annotation placed at the beginning/end of each `namespace absl` scope.
80 // This is used to inject an inline namespace.
81 //
82 // The proper way to write Abseil code in the `absl` namespace is:
83 //
84 // namespace absl {
85 // ABSL_NAMESPACE_BEGIN
86 //
87 // void Foo();  // absl::Foo().
88 //
89 // ABSL_NAMESPACE_END
90 // }  // namespace absl
91 //
92 // Users of Abseil should not use these macros, because users of Abseil should
93 // not write `namespace absl {` in their own code for any reason.  (Abseil does
94 // not support forward declarations of its own types, nor does it support
95 // user-provided specialization of Abseil templates.  Code that violates these
96 // rules may be broken without warning.)
97 #if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \
98     !defined(ABSL_OPTION_INLINE_NAMESPACE_NAME)
99 #error options.h is misconfigured.
100 #endif
101 
102 // Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
103 #if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1
104 
105 #define ABSL_INTERNAL_INLINE_NAMESPACE_STR \
106   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME)
107 
108 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
109               "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
110               "not be empty.");
111 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
112                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
113                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
114                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
115                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
116               "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
117               "be changed to a new, unique identifier name.");
118 
119 #endif
120 
121 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
122 #define ABSL_NAMESPACE_BEGIN
123 #define ABSL_NAMESPACE_END
124 #elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
125 #define ABSL_NAMESPACE_BEGIN \
126   inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
127 #define ABSL_NAMESPACE_END }
128 #else
129 #error options.h is misconfigured.
130 #endif
131 
132 // -----------------------------------------------------------------------------
133 // Compiler Feature Checks
134 // -----------------------------------------------------------------------------
135 
136 // ABSL_HAVE_BUILTIN()
137 //
138 // Checks whether the compiler supports a Clang Feature Checking Macro, and if
139 // so, checks whether it supports the provided builtin function "x" where x
140 // is one of the functions noted in
141 // https://clang.llvm.org/docs/LanguageExtensions.html
142 //
143 // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
144 // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
145 #ifdef __has_builtin
146 #define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
147 #else
148 #define ABSL_HAVE_BUILTIN(x) 0
149 #endif
150 
151 #if defined(__is_identifier)
152 #define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
153 #else
154 #define ABSL_INTERNAL_HAS_KEYWORD(x) 0
155 #endif
156 
157 // ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
158 // We assume __thread is supported on Linux when compiled with Clang or compiled
159 // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
160 #ifdef ABSL_HAVE_TLS
161 #error ABSL_HAVE_TLS cannot be directly set
162 #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
163 #define ABSL_HAVE_TLS 1
164 #endif
165 
166 // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
167 //
168 // Checks whether `std::is_trivially_destructible<T>` is supported.
169 //
170 // Notes: All supported compilers using libc++ support this feature, as does
171 // gcc >= 4.8.1 using libstdc++, and Visual Studio.
172 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
173 #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
174 #elif defined(_LIBCPP_VERSION) ||                                        \
175     (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
176      (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) ||        \
177     defined(_MSC_VER)
178 #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
179 #endif
180 
181 // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
182 //
183 // Checks whether `std::is_trivially_default_constructible<T>` and
184 // `std::is_trivially_copy_constructible<T>` are supported.
185 
186 // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
187 //
188 // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
189 
190 // Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
191 // either libc++ or libstdc++, and Visual Studio (but not NVCC).
192 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
193 #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
194 #elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
195 #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
196 #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) ||        \
197     (!defined(__clang__) && defined(__GNUC__) &&                 \
198      (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \
199      (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) ||      \
200     (defined(_MSC_VER) && !defined(__NVCC__))
201 #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
202 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
203 #endif
204 
205 // ABSL_HAVE_SOURCE_LOCATION_CURRENT
206 //
207 // Indicates whether `absl::SourceLocation::current()` will return useful
208 // information in some contexts.
209 #ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
210 #if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
211     ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
212 #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
213 #endif
214 #endif
215 
216 // ABSL_HAVE_THREAD_LOCAL
217 //
218 // Checks whether C++11's `thread_local` storage duration specifier is
219 // supported.
220 #ifdef ABSL_HAVE_THREAD_LOCAL
221 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set
222 #elif defined(__APPLE__)
223 // Notes:
224 // * Xcode's clang did not support `thread_local` until version 8, and
225 //   even then not for all iOS < 9.0.
226 // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
227 //   targeting iOS 9.x.
228 // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
229 //   making __has_feature unreliable there.
230 //
231 // Otherwise, `__has_feature` is only supported by Clang so it has be inside
232 // `defined(__APPLE__)` check.
233 #if __has_feature(cxx_thread_local) && \
234     !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
235 #define ABSL_HAVE_THREAD_LOCAL 1
236 #endif
237 #else  // !defined(__APPLE__)
238 #define ABSL_HAVE_THREAD_LOCAL 1
239 #endif
240 
241 // There are platforms for which TLS should not be used even though the compiler
242 // makes it seem like it's supported (Android NDK < r12b for example).
243 // This is primarily because of linker problems and toolchain misconfiguration:
244 // Abseil does not intend to support this indefinitely. Currently, the newest
245 // toolchain that we intend to support that requires this behavior is the
246 // r11 NDK - allowing for a 5 year support window on that means this option
247 // is likely to be removed around June of 2021.
248 // TLS isn't supported until NDK r12b per
249 // https://developer.android.com/ndk/downloads/revision_history.html
250 // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
251 // <android/ndk-version.h>. For NDK < r16, users should define these macros,
252 // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
253 #if defined(__ANDROID__) && defined(__clang__)
254 #if __has_include(<android/ndk-version.h>)
255 #include <android/ndk-version.h>
256 #endif  // __has_include(<android/ndk-version.h>)
257 #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
258     defined(__NDK_MINOR__) &&                                               \
259     ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
260 #undef ABSL_HAVE_TLS
261 #undef ABSL_HAVE_THREAD_LOCAL
262 #endif
263 #endif  // defined(__ANDROID__) && defined(__clang__)
264 
265 // ABSL_HAVE_INTRINSIC_INT128
266 //
267 // Checks whether the __int128 compiler extension for a 128-bit integral type is
268 // supported.
269 //
270 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
271 // supported, but we avoid using it in certain cases:
272 // * On Clang:
273 //   * Building using Clang for Windows, where the Clang runtime library has
274 //     128-bit support only on LP64 architectures, but Windows is LLP64.
275 // * On Nvidia's nvcc:
276 //   * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
277 //     actually support __int128.
278 #ifdef ABSL_HAVE_INTRINSIC_INT128
279 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
280 #elif defined(__SIZEOF_INT128__)
281 #if (defined(__clang__) && !defined(_WIN32)) || \
282     (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) ||                \
283     (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
284 #define ABSL_HAVE_INTRINSIC_INT128 1
285 #elif defined(__CUDACC__)
286 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
287 // string explaining that it has been removed starting with CUDA 9. We use
288 // nested #ifs because there is no short-circuiting in the preprocessor.
289 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
290 #if __CUDACC_VER__ >= 70000
291 #define ABSL_HAVE_INTRINSIC_INT128 1
292 #endif  // __CUDACC_VER__ >= 70000
293 #endif  // defined(__CUDACC__)
294 #endif  // ABSL_HAVE_INTRINSIC_INT128
295 
296 // ABSL_HAVE_EXCEPTIONS
297 //
298 // Checks whether the compiler both supports and enables exceptions. Many
299 // compilers support a "no exceptions" mode that disables exceptions.
300 //
301 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
302 //
303 // * Code using `throw` and `try` may not compile.
304 // * The `noexcept` specifier will still compile and behave as normal.
305 // * The `noexcept` operator may still return `false`.
306 //
307 // For further details, consult the compiler's documentation.
308 #ifdef ABSL_HAVE_EXCEPTIONS
309 #error ABSL_HAVE_EXCEPTIONS cannot be directly set.
310 
311 #elif defined(__clang__)
312 
313 #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
314 // Clang >= 3.6
315 #if __has_feature(cxx_exceptions)
316 #define ABSL_HAVE_EXCEPTIONS 1
317 #endif  // __has_feature(cxx_exceptions)
318 #else
319 // Clang < 3.6
320 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
321 #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
322 #define ABSL_HAVE_EXCEPTIONS 1
323 #endif  // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
324 #endif  // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
325 
326 // Handle remaining special cases and default to exceptions being supported.
327 #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) &&    \
328     !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
329     !(defined(_MSC_VER) && !defined(_CPPUNWIND))
330 #define ABSL_HAVE_EXCEPTIONS 1
331 #endif
332 
333 // -----------------------------------------------------------------------------
334 // Platform Feature Checks
335 // -----------------------------------------------------------------------------
336 
337 // Currently supported operating systems and associated preprocessor
338 // symbols:
339 //
340 //   Linux and Linux-derived           __linux__
341 //   Android                           __ANDROID__ (implies __linux__)
342 //   Linux (non-Android)               __linux__ && !__ANDROID__
343 //   Darwin (macOS and iOS)            __APPLE__
344 //   Akaros (http://akaros.org)        __ros__
345 //   Windows                           _WIN32
346 //   NaCL                              __native_client__
347 //   AsmJS                             __asmjs__
348 //   WebAssembly                       __wasm__
349 //   Fuchsia                           __Fuchsia__
350 //
351 // Note that since Android defines both __ANDROID__ and __linux__, one
352 // may probe for either Linux or Android by simply testing for __linux__.
353 
354 // ABSL_HAVE_MMAP
355 //
356 // Checks whether the platform has an mmap(2) implementation as defined in
357 // POSIX.1-2001.
358 #ifdef ABSL_HAVE_MMAP
359 #error ABSL_HAVE_MMAP cannot be directly set
360 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||   \
361     defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
362     defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
363     defined(__ASYLO__)
364 #define ABSL_HAVE_MMAP 1
365 #endif
366 
367 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM
368 //
369 // Checks whether the platform implements the pthread_(get|set)schedparam(3)
370 // functions as defined in POSIX.1-2001.
371 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
372 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
373 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
374     defined(__ros__)
375 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
376 #endif
377 
378 // ABSL_HAVE_SCHED_YIELD
379 //
380 // Checks whether the platform implements sched_yield(2) as defined in
381 // POSIX.1-2001.
382 #ifdef ABSL_HAVE_SCHED_YIELD
383 #error ABSL_HAVE_SCHED_YIELD cannot be directly set
384 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
385 #define ABSL_HAVE_SCHED_YIELD 1
386 #endif
387 
388 // ABSL_HAVE_SEMAPHORE_H
389 //
390 // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
391 // family of functions as standardized in POSIX.1-2001.
392 //
393 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
394 // explicitly deprecated and will cause build failures if enabled for those
395 // platforms.  We side-step the issue by not defining it here for Apple
396 // platforms.
397 #ifdef ABSL_HAVE_SEMAPHORE_H
398 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set
399 #elif defined(__linux__) || defined(__ros__)
400 #define ABSL_HAVE_SEMAPHORE_H 1
401 #endif
402 
403 // ABSL_HAVE_ALARM
404 //
405 // Checks whether the platform supports the <signal.h> header and alarm(2)
406 // function as standardized in POSIX.1-2001.
407 #ifdef ABSL_HAVE_ALARM
408 #error ABSL_HAVE_ALARM cannot be directly set
409 #elif defined(__GOOGLE_GRTE_VERSION__)
410 // feature tests for Google's GRTE
411 #define ABSL_HAVE_ALARM 1
412 #elif defined(__GLIBC__)
413 // feature test for glibc
414 #define ABSL_HAVE_ALARM 1
415 #elif defined(_MSC_VER)
416 // feature tests for Microsoft's library
417 #elif defined(__MINGW32__)
418 // mingw32 doesn't provide alarm(2):
419 // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
420 // mingw-w64 provides a no-op implementation:
421 // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
422 #elif defined(__EMSCRIPTEN__)
423 // emscripten doesn't support signals
424 #elif defined(__Fuchsia__)
425 // Signals don't exist on fuchsia.
426 #elif defined(__native_client__)
427 #else
428 // other standard libraries
429 #define ABSL_HAVE_ALARM 1
430 #endif
431 
432 // ABSL_IS_LITTLE_ENDIAN
433 // ABSL_IS_BIG_ENDIAN
434 //
435 // Checks the endianness of the platform.
436 //
437 // Notes: uses the built in endian macros provided by GCC (since 4.6) and
438 // Clang (since 3.2); see
439 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
440 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
441 #if defined(ABSL_IS_BIG_ENDIAN)
442 #error "ABSL_IS_BIG_ENDIAN cannot be directly set."
443 #endif
444 #if defined(ABSL_IS_LITTLE_ENDIAN)
445 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
446 #endif
447 
448 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
449      __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
450 #define ABSL_IS_LITTLE_ENDIAN 1
451 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
452     __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
453 #define ABSL_IS_BIG_ENDIAN 1
454 #elif defined(_WIN32)
455 #define ABSL_IS_LITTLE_ENDIAN 1
456 #else
457 #error "absl endian detection needs to be set up for your compiler"
458 #endif
459 
460 // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
461 // even though the headers exist and are publicly noted to work.  See
462 // https://github.com/abseil/abseil-cpp/issues/207 and
463 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
464 // libc++ spells out the availability requirements in the file
465 // llvm-project/libcxx/include/__config via the #define
466 // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
467 #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
468   ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
469    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
470   (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
471    __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
472   (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
473    __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 120000) || \
474   (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
475    __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 50000))
476 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
477 #else
478 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
479 #endif
480 
481 // ABSL_HAVE_STD_ANY
482 //
483 // Checks whether C++17 std::any is available by checking whether <any> exists.
484 #ifdef ABSL_HAVE_STD_ANY
485 #error "ABSL_HAVE_STD_ANY cannot be directly set."
486 #endif
487 
488 #ifdef __has_include
489 #if __has_include(<any>) && __cplusplus >= 201703L && \
490     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
491 #define ABSL_HAVE_STD_ANY 1
492 #endif
493 #endif
494 
495 // ABSL_HAVE_STD_OPTIONAL
496 //
497 // Checks whether C++17 std::optional is available.
498 #ifdef ABSL_HAVE_STD_OPTIONAL
499 #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
500 #endif
501 
502 #ifdef __has_include
503 #if __has_include(<optional>) && __cplusplus >= 201703L && \
504     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
505 #define ABSL_HAVE_STD_OPTIONAL 1
506 #endif
507 #endif
508 
509 // ABSL_HAVE_STD_VARIANT
510 //
511 // Checks whether C++17 std::variant is available.
512 #ifdef ABSL_HAVE_STD_VARIANT
513 #error "ABSL_HAVE_STD_VARIANT cannot be directly set."
514 #endif
515 
516 #ifdef __has_include
517 #if __has_include(<variant>) && __cplusplus >= 201703L && \
518     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
519 #define ABSL_HAVE_STD_VARIANT 1
520 #endif
521 #endif
522 
523 // ABSL_HAVE_STD_STRING_VIEW
524 //
525 // Checks whether C++17 std::string_view is available.
526 #ifdef ABSL_HAVE_STD_STRING_VIEW
527 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
528 #endif
529 
530 #ifdef __has_include
531 #if __has_include(<string_view>) && __cplusplus >= 201703L
532 #define ABSL_HAVE_STD_STRING_VIEW 1
533 #endif
534 #endif
535 
536 // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
537 // the support for <optional>, <any>, <string_view>, <variant>. So we use
538 // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
539 // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
540 // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
541 // version.
542 // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
543 #if defined(_MSC_VER) && _MSC_VER >= 1910 && \
544     ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
545 // #define ABSL_HAVE_STD_ANY 1
546 #define ABSL_HAVE_STD_OPTIONAL 1
547 #define ABSL_HAVE_STD_VARIANT 1
548 #define ABSL_HAVE_STD_STRING_VIEW 1
549 #endif
550 
551 // ABSL_USES_STD_ANY
552 //
553 // Indicates whether absl::any is an alias for std::any.
554 #if !defined(ABSL_OPTION_USE_STD_ANY)
555 #error options.h is misconfigured.
556 #elif ABSL_OPTION_USE_STD_ANY == 0 || \
557     (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
558 #undef ABSL_USES_STD_ANY
559 #elif ABSL_OPTION_USE_STD_ANY == 1 || \
560     (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
561 #define ABSL_USES_STD_ANY 1
562 #else
563 #error options.h is misconfigured.
564 #endif
565 
566 // ABSL_USES_STD_OPTIONAL
567 //
568 // Indicates whether absl::optional is an alias for std::optional.
569 #if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
570 #error options.h is misconfigured.
571 #elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
572     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
573 #undef ABSL_USES_STD_OPTIONAL
574 #elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
575     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
576 #define ABSL_USES_STD_OPTIONAL 1
577 #else
578 #error options.h is misconfigured.
579 #endif
580 
581 // ABSL_USES_STD_VARIANT
582 //
583 // Indicates whether absl::variant is an alias for std::variant.
584 #if !defined(ABSL_OPTION_USE_STD_VARIANT)
585 #error options.h is misconfigured.
586 #elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
587     (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
588 #undef ABSL_USES_STD_VARIANT
589 #elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
590     (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
591 #define ABSL_USES_STD_VARIANT 1
592 #else
593 #error options.h is misconfigured.
594 #endif
595 
596 // ABSL_USES_STD_STRING_VIEW
597 //
598 // Indicates whether absl::string_view is an alias for std::string_view.
599 #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
600 #error options.h is misconfigured.
601 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
602     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
603      !defined(ABSL_HAVE_STD_STRING_VIEW))
604 #undef ABSL_USES_STD_STRING_VIEW
605 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
606     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
607      defined(ABSL_HAVE_STD_STRING_VIEW))
608 #define ABSL_USES_STD_STRING_VIEW 1
609 #else
610 #error options.h is misconfigured.
611 #endif
612 
613 // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
614 // SEH exception from emplace for variant<SomeStruct> when constructing the
615 // struct can throw. This defeats some of variant_test and
616 // variant_exception_safety_test.
617 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
618 #define ABSL_INTERNAL_MSVC_2017_DBG_MODE
619 #endif
620 
621 // ABSL_INTERNAL_MANGLED_NS
622 // ABSL_INTERNAL_MANGLED_BACKREFERENCE
623 //
624 // Internal macros for building up mangled names in our internal fork of CCTZ.
625 // This implementation detail is only needed and provided for the MSVC build.
626 //
627 // These macros both expand to string literals.  ABSL_INTERNAL_MANGLED_NS is
628 // the mangled spelling of the `absl` namespace, and
629 // ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
630 // the proper count to skip past the CCTZ fork namespace names.  (This number
631 // is one larger when there is an inline namespace name to skip.)
632 #if defined(_MSC_VER)
633 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
634 #define ABSL_INTERNAL_MANGLED_NS "absl"
635 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
636 #else
637 #define ABSL_INTERNAL_MANGLED_NS \
638   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
639 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
640 #endif
641 #endif
642 
643 #undef ABSL_INTERNAL_HAS_KEYWORD
644 
645 // ABSL_DLL
646 //
647 // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
648 // so we can annotate symbols appropriately as being exported. When used in
649 // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
650 // that consumers know the symbol is defined inside the DLL. In all other cases,
651 // the macro expands to nothing.
652 #if defined(_MSC_VER)
653 #if defined(ABSL_BUILD_DLL)
654 #define ABSL_DLL __declspec(dllexport)
655 #elif defined(ABSL_CONSUME_DLL)
656 #define ABSL_DLL __declspec(dllimport)
657 #else
658 #define ABSL_DLL
659 #endif
660 #else
661 #define ABSL_DLL
662 #endif  // defined(_MSC_VER)
663 
664 #endif  // ABSL_BASE_CONFIG_H_
665