• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Emscripten doesn't yet support `thread_local` or `__thread`.
266 // https://github.com/emscripten-core/emscripten/issues/3502
267 #if defined(__EMSCRIPTEN__)
268 #undef ABSL_HAVE_TLS
269 #undef ABSL_HAVE_THREAD_LOCAL
270 #endif  // defined(__EMSCRIPTEN__)
271 
272 // ABSL_HAVE_INTRINSIC_INT128
273 //
274 // Checks whether the __int128 compiler extension for a 128-bit integral type is
275 // supported.
276 //
277 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
278 // supported, but we avoid using it in certain cases:
279 // * On Clang:
280 //   * Building using Clang for Windows, where the Clang runtime library has
281 //     128-bit support only on LP64 architectures, but Windows is LLP64.
282 // * On Nvidia's nvcc:
283 //   * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
284 //     actually support __int128.
285 #ifdef ABSL_HAVE_INTRINSIC_INT128
286 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
287 #elif defined(__SIZEOF_INT128__)
288 #if (defined(__clang__) && !defined(_WIN32)) || \
289     (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) ||                \
290     (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
291 #define ABSL_HAVE_INTRINSIC_INT128 1
292 #elif defined(__CUDACC__)
293 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
294 // string explaining that it has been removed starting with CUDA 9. We use
295 // nested #ifs because there is no short-circuiting in the preprocessor.
296 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
297 #if __CUDACC_VER__ >= 70000
298 #define ABSL_HAVE_INTRINSIC_INT128 1
299 #endif  // __CUDACC_VER__ >= 70000
300 #endif  // defined(__CUDACC__)
301 #endif  // ABSL_HAVE_INTRINSIC_INT128
302 
303 // ABSL_HAVE_EXCEPTIONS
304 //
305 // Checks whether the compiler both supports and enables exceptions. Many
306 // compilers support a "no exceptions" mode that disables exceptions.
307 //
308 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
309 //
310 // * Code using `throw` and `try` may not compile.
311 // * The `noexcept` specifier will still compile and behave as normal.
312 // * The `noexcept` operator may still return `false`.
313 //
314 // For further details, consult the compiler's documentation.
315 #ifdef ABSL_HAVE_EXCEPTIONS
316 #error ABSL_HAVE_EXCEPTIONS cannot be directly set.
317 
318 #elif defined(__clang__)
319 
320 #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
321 // Clang >= 3.6
322 #if __has_feature(cxx_exceptions)
323 #define ABSL_HAVE_EXCEPTIONS 1
324 #endif  // __has_feature(cxx_exceptions)
325 #else
326 // Clang < 3.6
327 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
328 #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
329 #define ABSL_HAVE_EXCEPTIONS 1
330 #endif  // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
331 #endif  // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
332 
333 // Handle remaining special cases and default to exceptions being supported.
334 #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) &&    \
335     !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
336     !(defined(_MSC_VER) && !defined(_CPPUNWIND))
337 #define ABSL_HAVE_EXCEPTIONS 1
338 #endif
339 
340 // -----------------------------------------------------------------------------
341 // Platform Feature Checks
342 // -----------------------------------------------------------------------------
343 
344 // Currently supported operating systems and associated preprocessor
345 // symbols:
346 //
347 //   Linux and Linux-derived           __linux__
348 //   Android                           __ANDROID__ (implies __linux__)
349 //   Linux (non-Android)               __linux__ && !__ANDROID__
350 //   Darwin (macOS and iOS)            __APPLE__
351 //   Akaros (http://akaros.org)        __ros__
352 //   Windows                           _WIN32
353 //   NaCL                              __native_client__
354 //   AsmJS                             __asmjs__
355 //   WebAssembly                       __wasm__
356 //   Fuchsia                           __Fuchsia__
357 //
358 // Note that since Android defines both __ANDROID__ and __linux__, one
359 // may probe for either Linux or Android by simply testing for __linux__.
360 
361 // ABSL_HAVE_MMAP
362 //
363 // Checks whether the platform has an mmap(2) implementation as defined in
364 // POSIX.1-2001.
365 #ifdef ABSL_HAVE_MMAP
366 #error ABSL_HAVE_MMAP cannot be directly set
367 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||   \
368     defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
369     defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
370     defined(__ASYLO__)
371 #define ABSL_HAVE_MMAP 1
372 #endif
373 
374 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM
375 //
376 // Checks whether the platform implements the pthread_(get|set)schedparam(3)
377 // functions as defined in POSIX.1-2001.
378 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
379 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
380 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
381     defined(__ros__)
382 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
383 #endif
384 
385 // ABSL_HAVE_SCHED_YIELD
386 //
387 // Checks whether the platform implements sched_yield(2) as defined in
388 // POSIX.1-2001.
389 #ifdef ABSL_HAVE_SCHED_YIELD
390 #error ABSL_HAVE_SCHED_YIELD cannot be directly set
391 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
392 #define ABSL_HAVE_SCHED_YIELD 1
393 #endif
394 
395 // ABSL_HAVE_SEMAPHORE_H
396 //
397 // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
398 // family of functions as standardized in POSIX.1-2001.
399 //
400 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
401 // explicitly deprecated and will cause build failures if enabled for those
402 // platforms.  We side-step the issue by not defining it here for Apple
403 // platforms.
404 #ifdef ABSL_HAVE_SEMAPHORE_H
405 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set
406 #elif defined(__linux__) || defined(__ros__)
407 #define ABSL_HAVE_SEMAPHORE_H 1
408 #endif
409 
410 // ABSL_HAVE_ALARM
411 //
412 // Checks whether the platform supports the <signal.h> header and alarm(2)
413 // function as standardized in POSIX.1-2001.
414 #ifdef ABSL_HAVE_ALARM
415 #error ABSL_HAVE_ALARM cannot be directly set
416 #elif defined(__GOOGLE_GRTE_VERSION__)
417 // feature tests for Google's GRTE
418 #define ABSL_HAVE_ALARM 1
419 #elif defined(__GLIBC__)
420 // feature test for glibc
421 #define ABSL_HAVE_ALARM 1
422 #elif defined(_MSC_VER)
423 // feature tests for Microsoft's library
424 #elif defined(__MINGW32__)
425 // mingw32 doesn't provide alarm(2):
426 // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
427 // mingw-w64 provides a no-op implementation:
428 // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
429 #elif defined(__EMSCRIPTEN__)
430 // emscripten doesn't support signals
431 #elif defined(__Fuchsia__)
432 // Signals don't exist on fuchsia.
433 #elif defined(__native_client__)
434 #else
435 // other standard libraries
436 #define ABSL_HAVE_ALARM 1
437 #endif
438 
439 // ABSL_IS_LITTLE_ENDIAN
440 // ABSL_IS_BIG_ENDIAN
441 //
442 // Checks the endianness of the platform.
443 //
444 // Notes: uses the built in endian macros provided by GCC (since 4.6) and
445 // Clang (since 3.2); see
446 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
447 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
448 #if defined(ABSL_IS_BIG_ENDIAN)
449 #error "ABSL_IS_BIG_ENDIAN cannot be directly set."
450 #endif
451 #if defined(ABSL_IS_LITTLE_ENDIAN)
452 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
453 #endif
454 
455 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
456      __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
457 #define ABSL_IS_LITTLE_ENDIAN 1
458 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
459     __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
460 #define ABSL_IS_BIG_ENDIAN 1
461 #elif defined(_WIN32)
462 #define ABSL_IS_LITTLE_ENDIAN 1
463 #else
464 #error "absl endian detection needs to be set up for your compiler"
465 #endif
466 
467 // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
468 // even though the headers exist and are publicly noted to work.  See
469 // https://github.com/abseil/abseil-cpp/issues/207 and
470 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
471 // libc++ spells out the availability requirements in the file
472 // llvm-project/libcxx/include/__config via the #define
473 // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
474 #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
475   ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
476    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
477   (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
478    __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
479   (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
480    __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 120000) || \
481   (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
482    __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 50000))
483 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
484 #else
485 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
486 #endif
487 
488 // ABSL_HAVE_STD_ANY
489 //
490 // Checks whether C++17 std::any is available by checking whether <any> exists.
491 #ifdef ABSL_HAVE_STD_ANY
492 #error "ABSL_HAVE_STD_ANY cannot be directly set."
493 #endif
494 
495 #ifdef __has_include
496 #if __has_include(<any>) && __cplusplus >= 201703L && \
497     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
498 #define ABSL_HAVE_STD_ANY 1
499 #endif
500 #endif
501 
502 // ABSL_HAVE_STD_OPTIONAL
503 //
504 // Checks whether C++17 std::optional is available.
505 #ifdef ABSL_HAVE_STD_OPTIONAL
506 #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
507 #endif
508 
509 #ifdef __has_include
510 #if __has_include(<optional>) && __cplusplus >= 201703L && \
511     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
512 #define ABSL_HAVE_STD_OPTIONAL 1
513 #endif
514 #endif
515 
516 // ABSL_HAVE_STD_VARIANT
517 //
518 // Checks whether C++17 std::variant is available.
519 #ifdef ABSL_HAVE_STD_VARIANT
520 #error "ABSL_HAVE_STD_VARIANT cannot be directly set."
521 #endif
522 
523 #ifdef __has_include
524 #if __has_include(<variant>) && __cplusplus >= 201703L && \
525     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
526 #define ABSL_HAVE_STD_VARIANT 1
527 #endif
528 #endif
529 
530 // ABSL_HAVE_STD_STRING_VIEW
531 //
532 // Checks whether C++17 std::string_view is available.
533 #ifdef ABSL_HAVE_STD_STRING_VIEW
534 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
535 #endif
536 
537 #ifdef __has_include
538 #if __has_include(<string_view>) && __cplusplus >= 201703L
539 #define ABSL_HAVE_STD_STRING_VIEW 1
540 #endif
541 #endif
542 
543 // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
544 // the support for <optional>, <any>, <string_view>, <variant>. So we use
545 // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
546 // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
547 // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
548 // version.
549 // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
550 #if defined(_MSC_VER) && _MSC_VER >= 1910 && \
551     ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
552 // #define ABSL_HAVE_STD_ANY 1
553 #define ABSL_HAVE_STD_OPTIONAL 1
554 #define ABSL_HAVE_STD_VARIANT 1
555 #define ABSL_HAVE_STD_STRING_VIEW 1
556 #endif
557 
558 // ABSL_USES_STD_ANY
559 //
560 // Indicates whether absl::any is an alias for std::any.
561 #if !defined(ABSL_OPTION_USE_STD_ANY)
562 #error options.h is misconfigured.
563 #elif ABSL_OPTION_USE_STD_ANY == 0 || \
564     (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
565 #undef ABSL_USES_STD_ANY
566 #elif ABSL_OPTION_USE_STD_ANY == 1 || \
567     (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
568 #define ABSL_USES_STD_ANY 1
569 #else
570 #error options.h is misconfigured.
571 #endif
572 
573 // ABSL_USES_STD_OPTIONAL
574 //
575 // Indicates whether absl::optional is an alias for std::optional.
576 #if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
577 #error options.h is misconfigured.
578 #elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
579     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
580 #undef ABSL_USES_STD_OPTIONAL
581 #elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
582     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
583 #define ABSL_USES_STD_OPTIONAL 1
584 #else
585 #error options.h is misconfigured.
586 #endif
587 
588 // ABSL_USES_STD_VARIANT
589 //
590 // Indicates whether absl::variant is an alias for std::variant.
591 #if !defined(ABSL_OPTION_USE_STD_VARIANT)
592 #error options.h is misconfigured.
593 #elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
594     (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
595 #undef ABSL_USES_STD_VARIANT
596 #elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
597     (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
598 #define ABSL_USES_STD_VARIANT 1
599 #else
600 #error options.h is misconfigured.
601 #endif
602 
603 // ABSL_USES_STD_STRING_VIEW
604 //
605 // Indicates whether absl::string_view is an alias for std::string_view.
606 #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
607 #error options.h is misconfigured.
608 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
609     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
610      !defined(ABSL_HAVE_STD_STRING_VIEW))
611 #undef ABSL_USES_STD_STRING_VIEW
612 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
613     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
614      defined(ABSL_HAVE_STD_STRING_VIEW))
615 #define ABSL_USES_STD_STRING_VIEW 1
616 #else
617 #error options.h is misconfigured.
618 #endif
619 
620 // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
621 // SEH exception from emplace for variant<SomeStruct> when constructing the
622 // struct can throw. This defeats some of variant_test and
623 // variant_exception_safety_test.
624 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
625 #define ABSL_INTERNAL_MSVC_2017_DBG_MODE
626 #endif
627 
628 // ABSL_INTERNAL_MANGLED_NS
629 // ABSL_INTERNAL_MANGLED_BACKREFERENCE
630 //
631 // Internal macros for building up mangled names in our internal fork of CCTZ.
632 // This implementation detail is only needed and provided for the MSVC build.
633 //
634 // These macros both expand to string literals.  ABSL_INTERNAL_MANGLED_NS is
635 // the mangled spelling of the `absl` namespace, and
636 // ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
637 // the proper count to skip past the CCTZ fork namespace names.  (This number
638 // is one larger when there is an inline namespace name to skip.)
639 #if defined(_MSC_VER)
640 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
641 #define ABSL_INTERNAL_MANGLED_NS "absl"
642 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
643 #else
644 #define ABSL_INTERNAL_MANGLED_NS \
645   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
646 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
647 #endif
648 #endif
649 
650 #undef ABSL_INTERNAL_HAS_KEYWORD
651 
652 // ABSL_DLL
653 //
654 // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
655 // so we can annotate symbols appropriately as being exported. When used in
656 // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
657 // that consumers know the symbol is defined inside the DLL. In all other cases,
658 // the macro expands to nothing.
659 #if defined(_MSC_VER)
660 #if defined(ABSL_BUILD_DLL)
661 #define ABSL_DLL __declspec(dllexport)
662 #elif defined(ABSL_CONSUME_DLL)
663 #define ABSL_DLL __declspec(dllimport)
664 #else
665 #define ABSL_DLL
666 #endif
667 #else
668 #define ABSL_DLL
669 #endif  // defined(_MSC_VER)
670 
671 #endif  // ABSL_BASE_CONFIG_H_
672