Bug 932076 - Add check for MediaExtractor creation failure. r=doublec
[gecko.git] / mfbt / Compiler.h
blobfd5c98c98d0ab60f03e8787be2386e0e60f5a9e3
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 #if !defined(__clang__) && defined(__GNUC__)
14 #define MOZ_IS_GCC 1
16 * This macro should simplify gcc version checking. For example, to check
17 * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`.
19 # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \
20 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
21 >= ((major) * 10000 + (minor) * 100 + (patchlevel)))
22 #if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0)
23 # error "mfbt (and Gecko) require at least gcc 4.4 to build."
24 #endif
26 #else
28 #define MOZ_IS_GCC 0
30 #endif
33 * The situation with standard libraries is a lot worse than with compilers,
34 * particularly as clang and gcc could end up using one of three or so standard
35 * libraries, and they may not be up-to-snuff with newer C++11 versions. To
36 * detect the library, we're going to include cstddef (which is a small header
37 * which will be transitively included by everybody else at some point) to grab
38 * the version macros and deduce macros from there.
40 #ifdef __cplusplus
41 # include <cstddef>
42 # ifdef _STLPORT_MAJOR
43 # define MOZ_USING_STLPORT 1
44 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
45 (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
46 # elif defined(_LIBCPP_VERSION)
48 * libc++, unfortunately, doesn't appear to have useful versioning macros.
49 * Hopefully, the recommendations of N3694 with respect to standard libraries
50 * will get applied instead and we won't need to worry about version numbers
51 * here.
53 # define MOZ_USING_LIBCXX 1
54 # elif defined(__GLIBCXX__)
55 # define MOZ_USING_LIBSTDCXX 1
57 * libstdc++ is also annoying and doesn't give us useful versioning macros
58 * for the library. If we're using gcc, then assume that libstdc++ matches
59 * the compiler version. If we're using clang, we're going to have to fake
60 * major/minor combinations by looking for newly-defined config macros.
62 # if MOZ_IS_GCC
63 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
64 MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
65 # elif defined(_GLIBCXX_THROW_OR_ABORT)
66 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
67 ((major) < 4 || ((major) == 4 && (minor) <= 8))
68 # elif defined(_GLIBCXX_NOEXCEPT)
69 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
70 ((major) < 4 || ((major) == 4 && (minor) <= 7))
71 # elif defined(_GLIBCXX_USE_DEPRECATED)
72 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
73 ((major) < 4 || ((major) == 4 && (minor) <= 6))
74 # elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
75 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
76 ((major) < 4 || ((major) == 4 && (minor) <= 5))
77 # elif defined(_GLIBCXX_BEGIN_EXTERN_C)
78 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
79 ((major) < 4 || ((major) == 4 && (minor) <= 4))
80 # elif defined(_GLIBCXX_VISIBILITY_ATTR)
81 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
82 ((major) < 4 || ((major) == 4 && (minor) <= 3))
83 # elif defined(_GLIBCXX_VISIBILITY)
84 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
85 ((major) < 4 || ((major) == 4 && (minor) <= 2))
86 # else
87 # error "Your version of libstdc++ is unknown to us and is likely too old."
88 # endif
89 # endif
91 // Flesh out the defines for everyone else
92 # ifndef MOZ_USING_STLPORT
93 # define MOZ_USING_STLPORT 0
94 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
95 # endif
96 # ifndef MOZ_USING_LIBCXX
97 # define MOZ_USING_LIBCXX 0
98 # endif
99 # ifndef MOZ_USING_LIBSTDCXX
100 # define MOZ_USING_LIBSTDCXX 0
101 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
102 # endif
103 #endif /* __cplusplus */
105 #endif /* mozilla_Compiler_h */