clang.hpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // (C) Copyright Douglas Gregor 2010
  2. //
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for most recent version.
  7. // Clang compiler setup.
  8. #define BOOST_HAS_PRAGMA_ONCE
  9. // Detecting `-fms-extension` compiler flag assuming that _MSC_VER defined when that flag is used.
  10. #if defined (_MSC_VER) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
  11. # define BOOST_HAS_PRAGMA_DETECT_MISMATCH
  12. #endif
  13. // When compiling with clang before __has_extension was defined,
  14. // even if one writes 'defined(__has_extension) && __has_extension(xxx)',
  15. // clang reports a compiler error. So the only workaround found is:
  16. #ifndef __has_extension
  17. #define __has_extension __has_feature
  18. #endif
  19. #ifndef __has_attribute
  20. #define __has_attribute(x) 0
  21. #endif
  22. #if !__has_feature(cxx_exceptions) && !defined(BOOST_NO_EXCEPTIONS)
  23. # define BOOST_NO_EXCEPTIONS
  24. #endif
  25. #if !__has_feature(cxx_rtti) && !defined(BOOST_NO_RTTI)
  26. # define BOOST_NO_RTTI
  27. #endif
  28. #if !__has_feature(cxx_rtti) && !defined(BOOST_NO_TYPEID)
  29. # define BOOST_NO_TYPEID
  30. #endif
  31. #if defined(__int64) && !defined(__GNUC__)
  32. # define BOOST_HAS_MS_INT64
  33. #endif
  34. #define BOOST_HAS_NRVO
  35. // Branch prediction hints
  36. #if defined(__has_builtin)
  37. #if __has_builtin(__builtin_expect)
  38. #define BOOST_LIKELY(x) __builtin_expect(x, 1)
  39. #define BOOST_UNLIKELY(x) __builtin_expect(x, 0)
  40. #endif
  41. #endif
  42. // Clang supports "long long" in all compilation modes.
  43. #define BOOST_HAS_LONG_LONG
  44. //
  45. // We disable this if the compiler is really nvcc with C++03 as it
  46. // doesn't actually support __int128 as of CUDA_VERSION=7500
  47. // even though it defines __SIZEOF_INT128__.
  48. // See https://svn.boost.org/trac/boost/ticket/10418
  49. // https://svn.boost.org/trac/boost/ticket/11852
  50. // Only re-enable this for nvcc if you're absolutely sure
  51. // of the circumstances under which it's supported.
  52. // Similarly __SIZEOF_INT128__ is defined when targetting msvc
  53. // compatibility even though the required support functions are absent.
  54. //
  55. #if defined(__CUDACC__)
  56. # if defined(BOOST_GCC_CXX11)
  57. # define BOOST_NVCC_CXX11
  58. # else
  59. # define BOOST_NVCC_CXX03
  60. # endif
  61. #endif
  62. #if defined(__SIZEOF_INT128__) && !defined(BOOST_NVCC_CXX03) && !defined(_MSC_VER)
  63. # define BOOST_HAS_INT128
  64. #endif
  65. //
  66. // Dynamic shared object (DSO) and dynamic-link library (DLL) support
  67. //
  68. #if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
  69. # define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default")))
  70. # define BOOST_SYMBOL_IMPORT
  71. # define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
  72. #endif
  73. //
  74. // The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
  75. // between switch labels.
  76. //
  77. #if __cplusplus >= 201103L && defined(__has_warning)
  78. # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
  79. # define BOOST_FALLTHROUGH [[clang::fallthrough]]
  80. # endif
  81. #endif
  82. #if !__has_feature(cxx_auto_type)
  83. # define BOOST_NO_CXX11_AUTO_DECLARATIONS
  84. # define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS
  85. #endif
  86. //
  87. // Currently clang on Windows using VC++ RTL does not support C++11's char16_t or char32_t
  88. //
  89. #if defined(_MSC_VER) || !(defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
  90. # define BOOST_NO_CXX11_CHAR16_T
  91. # define BOOST_NO_CXX11_CHAR32_T
  92. #endif
  93. #if !__has_feature(cxx_constexpr)
  94. # define BOOST_NO_CXX11_CONSTEXPR
  95. #endif
  96. #if !__has_feature(cxx_decltype)
  97. # define BOOST_NO_CXX11_DECLTYPE
  98. #endif
  99. #if !__has_feature(cxx_decltype_incomplete_return_types)
  100. # define BOOST_NO_CXX11_DECLTYPE_N3276
  101. #endif
  102. #if !__has_feature(cxx_defaulted_functions)
  103. # define BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
  104. #endif
  105. #if !__has_feature(cxx_deleted_functions)
  106. # define BOOST_NO_CXX11_DELETED_FUNCTIONS
  107. #endif
  108. #if !__has_feature(cxx_explicit_conversions)
  109. # define BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  110. #endif
  111. #if !__has_feature(cxx_default_function_template_args)
  112. # define BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS
  113. #endif
  114. #if !__has_feature(cxx_generalized_initializers)
  115. # define BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  116. #endif
  117. #if !__has_feature(cxx_lambdas)
  118. # define BOOST_NO_CXX11_LAMBDAS
  119. #endif
  120. #if !__has_feature(cxx_local_type_template_args)
  121. # define BOOST_NO_CXX11_LOCAL_CLASS_TEMPLATE_PARAMETERS
  122. #endif
  123. #if !__has_feature(cxx_noexcept)
  124. # define BOOST_NO_CXX11_NOEXCEPT
  125. #endif
  126. #if !__has_feature(cxx_nullptr)
  127. # define BOOST_NO_CXX11_NULLPTR
  128. #endif
  129. #if !__has_feature(cxx_range_for)
  130. # define BOOST_NO_CXX11_RANGE_BASED_FOR
  131. #endif
  132. #if !__has_feature(cxx_raw_string_literals)
  133. # define BOOST_NO_CXX11_RAW_LITERALS
  134. #endif
  135. #if !__has_feature(cxx_reference_qualified_functions)
  136. # define BOOST_NO_CXX11_REF_QUALIFIERS
  137. #endif
  138. #if !__has_feature(cxx_generalized_initializers)
  139. # define BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  140. #endif
  141. #if !__has_feature(cxx_rvalue_references)
  142. # define BOOST_NO_CXX11_RVALUE_REFERENCES
  143. #endif
  144. #if !__has_feature(cxx_strong_enums)
  145. # define BOOST_NO_CXX11_SCOPED_ENUMS
  146. #endif
  147. #if !__has_feature(cxx_static_assert)
  148. # define BOOST_NO_CXX11_STATIC_ASSERT
  149. #endif
  150. #if !__has_feature(cxx_alias_templates)
  151. # define BOOST_NO_CXX11_TEMPLATE_ALIASES
  152. #endif
  153. #if !__has_feature(cxx_unicode_literals)
  154. # define BOOST_NO_CXX11_UNICODE_LITERALS
  155. #endif
  156. #if !__has_feature(cxx_variadic_templates)
  157. # define BOOST_NO_CXX11_VARIADIC_TEMPLATES
  158. #endif
  159. #if !__has_feature(cxx_user_literals)
  160. # define BOOST_NO_CXX11_USER_DEFINED_LITERALS
  161. #endif
  162. #if !__has_feature(cxx_alignas)
  163. # define BOOST_NO_CXX11_ALIGNAS
  164. #endif
  165. #if !__has_feature(cxx_trailing_return)
  166. # define BOOST_NO_CXX11_TRAILING_RESULT_TYPES
  167. #endif
  168. #if !__has_feature(cxx_inline_namespaces)
  169. # define BOOST_NO_CXX11_INLINE_NAMESPACES
  170. #endif
  171. #if !__has_feature(cxx_override_control)
  172. # define BOOST_NO_CXX11_FINAL
  173. #endif
  174. #if !(__has_feature(__cxx_binary_literals__) || __has_extension(__cxx_binary_literals__))
  175. # define BOOST_NO_CXX14_BINARY_LITERALS
  176. #endif
  177. #if !__has_feature(__cxx_decltype_auto__)
  178. # define BOOST_NO_CXX14_DECLTYPE_AUTO
  179. #endif
  180. #if !__has_feature(__cxx_aggregate_nsdmi__)
  181. # define BOOST_NO_CXX14_AGGREGATE_NSDMI
  182. #endif
  183. #if !__has_feature(__cxx_init_captures__)
  184. # define BOOST_NO_CXX14_INITIALIZED_LAMBDA_CAPTURES
  185. #endif
  186. #if !__has_feature(__cxx_generic_lambdas__)
  187. # define BOOST_NO_CXX14_GENERIC_LAMBDAS
  188. #endif
  189. // clang < 3.5 has a defect with dependent type, like following.
  190. //
  191. // template <class T>
  192. // constexpr typename enable_if<pred<T> >::type foo(T &)
  193. // { } // error: no return statement in constexpr function
  194. //
  195. // This issue also affects C++11 mode, but C++11 constexpr requires return stmt.
  196. // Therefore we don't care such case.
  197. //
  198. // Note that we can't check Clang version directly as the numbering system changes depending who's
  199. // creating the Clang release (see https://github.com/boostorg/config/pull/39#issuecomment-59927873)
  200. // so instead verify that we have a feature that was introduced at the same time as working C++14
  201. // constexpr (generic lambda's in this case):
  202. //
  203. #if !__has_feature(__cxx_generic_lambdas__) || !__has_feature(__cxx_relaxed_constexpr__)
  204. # define BOOST_NO_CXX14_CONSTEXPR
  205. #endif
  206. #if !__has_feature(__cxx_return_type_deduction__)
  207. # define BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION
  208. #endif
  209. #if !__has_feature(__cxx_variable_templates__)
  210. # define BOOST_NO_CXX14_VARIABLE_TEMPLATES
  211. #endif
  212. #if __cplusplus < 201400
  213. // All versions with __cplusplus above this value seem to support this:
  214. # define BOOST_NO_CXX14_DIGIT_SEPARATORS
  215. #endif
  216. //
  217. // __builtin_unreachable:
  218. #if defined(__has_builtin) && __has_builtin(__builtin_unreachable)
  219. #define BOOST_UNREACHABLE_RETURN(x) __builtin_unreachable();
  220. #endif
  221. // Clang has supported the 'unused' attribute since the first release.
  222. #define BOOST_ATTRIBUTE_UNUSED __attribute__((__unused__))
  223. #ifndef BOOST_COMPILER
  224. # define BOOST_COMPILER "Clang version " __clang_version__
  225. #endif
  226. // Macro used to identify the Clang compiler.
  227. #define BOOST_CLANG 1