Bug 1531915 [wpt PR 15578] - Fix flakiness of external/wpt/css/css-position/z-index...
[gecko.git] / mfbt / Compiler.h
blob8febc43ebc3c0d7f2197b711c3a6386fe0509a03
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Various compiler checks. */
9 #ifndef mozilla_Compiler_h
10 #define mozilla_Compiler_h
12 #define MOZ_IS_GCC 0
14 #if !defined(__clang__) && defined(__GNUC__)
16 # undef MOZ_IS_GCC
17 # define MOZ_IS_GCC 1
19 * These macros should simplify gcc version checking. For example, to check
20 * for gcc 4.7.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 7, 1)`.
22 # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \
23 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
24 ((major)*10000 + (minor)*100 + (patchlevel)))
25 # define MOZ_GCC_VERSION_AT_MOST(major, minor, patchlevel) \
26 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) <= \
27 ((major)*10000 + (minor)*100 + (patchlevel)))
28 # if !MOZ_GCC_VERSION_AT_LEAST(6, 1, 0)
29 # error "mfbt (and Gecko) require at least gcc 6.1 to build."
30 # endif
32 #endif
35 * The situation with standard libraries is a lot worse than with compilers,
36 * particularly as clang and gcc could end up using one of three or so standard
37 * libraries, and they may not be up-to-snuff with newer C++11 versions. To
38 * detect the library, we're going to include cstddef (which is a small header
39 * which will be transitively included by everybody else at some point) to grab
40 * the version macros and deduce macros from there.
42 #ifdef __cplusplus
43 # include <cstddef>
44 # ifdef _STLPORT_MAJOR
45 # define MOZ_USING_STLPORT 1
46 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
47 (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
48 # elif defined(_LIBCPP_VERSION)
50 * libc++, unfortunately, doesn't appear to have useful versioning macros.
51 * Hopefully, the recommendations of N3694 with respect to standard libraries
52 * will get applied instead and we won't need to worry about version numbers
53 * here.
55 # define MOZ_USING_LIBCXX 1
56 # elif defined(__GLIBCXX__)
57 # define MOZ_USING_LIBSTDCXX 1
59 * libstdc++ is also annoying and doesn't give us useful versioning macros
60 * for the library. If we're using gcc, then assume that libstdc++ matches
61 * the compiler version. If we're using clang, we're going to have to fake
62 * major/minor combinations by looking for newly-defined config macros.
64 # if MOZ_IS_GCC
65 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
66 MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
67 # elif defined(_GLIBCXX_THROW_OR_ABORT)
68 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
69 ((major) < 4 || ((major) == 4 && (minor) <= 8))
70 # elif defined(_GLIBCXX_NOEXCEPT)
71 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
72 ((major) < 4 || ((major) == 4 && (minor) <= 7))
73 # elif defined(_GLIBCXX_USE_DEPRECATED)
74 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
75 ((major) < 4 || ((major) == 4 && (minor) <= 6))
76 # elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
77 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
78 ((major) < 4 || ((major) == 4 && (minor) <= 5))
79 # elif defined(_GLIBCXX_BEGIN_EXTERN_C)
80 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
81 ((major) < 4 || ((major) == 4 && (minor) <= 4))
82 # elif defined(_GLIBCXX_VISIBILITY_ATTR)
83 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
84 ((major) < 4 || ((major) == 4 && (minor) <= 3))
85 # elif defined(_GLIBCXX_VISIBILITY)
86 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
87 ((major) < 4 || ((major) == 4 && (minor) <= 2))
88 # else
89 # error "Your version of libstdc++ is unknown to us and is likely too old."
90 # endif
91 # endif
93 // Flesh out the defines for everyone else
94 # ifndef MOZ_USING_STLPORT
95 # define MOZ_USING_STLPORT 0
96 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
97 # endif
98 # ifndef MOZ_USING_LIBCXX
99 # define MOZ_USING_LIBCXX 0
100 # endif
101 # ifndef MOZ_USING_LIBSTDCXX
102 # define MOZ_USING_LIBSTDCXX 0
103 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
104 # endif
105 #endif /* __cplusplus */
107 #endif /* mozilla_Compiler_h */