clang.hpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #ifndef __has_cpp_attribute
  23. #define __has_cpp_attribute(x) 0
  24. #endif
  25. #if !__has_feature(cxx_exceptions) && !defined(BOOST_NO_EXCEPTIONS)
  26. # define BOOST_NO_EXCEPTIONS
  27. #endif
  28. #if !__has_feature(cxx_rtti) && !defined(BOOST_NO_RTTI)
  29. # define BOOST_NO_RTTI
  30. #endif
  31. #if !__has_feature(cxx_rtti) && !defined(BOOST_NO_TYPEID)
  32. # define BOOST_NO_TYPEID
  33. #endif
  34. #if !__has_feature(cxx_thread_local)
  35. # define BOOST_NO_CXX11_THREAD_LOCAL
  36. #endif
  37. #ifdef __is_identifier
  38. #if !__is_identifier(__int64) && !defined(__GNUC__)
  39. # define BOOST_HAS_MS_INT64
  40. #endif
  41. #endif
  42. #if __has_include(<stdint.h>)
  43. # define BOOST_HAS_STDINT_H
  44. #endif
  45. #define BOOST_HAS_NRVO
  46. // Branch prediction hints
  47. #if !defined (__c2__) && defined(__has_builtin)
  48. #if __has_builtin(__builtin_expect)
  49. #define BOOST_LIKELY(x) __builtin_expect(x, 1)
  50. #define BOOST_UNLIKELY(x) __builtin_expect(x, 0)
  51. #endif
  52. #endif
  53. // Clang supports "long long" in all compilation modes.
  54. #define BOOST_HAS_LONG_LONG
  55. //
  56. // We disable this if the compiler is really nvcc with C++03 as it
  57. // doesn't actually support __int128 as of CUDA_VERSION=7500
  58. // even though it defines __SIZEOF_INT128__.
  59. // See https://svn.boost.org/trac/boost/ticket/10418
  60. // https://svn.boost.org/trac/boost/ticket/11852
  61. // Only re-enable this for nvcc if you're absolutely sure
  62. // of the circumstances under which it's supported.
  63. // Similarly __SIZEOF_INT128__ is defined when targetting msvc
  64. // compatibility even though the required support functions are absent.
  65. //
  66. #if defined(__CUDACC__)
  67. # if defined(BOOST_GCC_CXX11)
  68. # define BOOST_NVCC_CXX11
  69. # else
  70. # define BOOST_NVCC_CXX03
  71. # endif
  72. #endif
  73. #if defined(__SIZEOF_INT128__) && !defined(BOOST_NVCC_CXX03) && !defined(_MSC_VER)
  74. # define BOOST_HAS_INT128
  75. #endif
  76. //
  77. // Dynamic shared object (DSO) and dynamic-link library (DLL) support
  78. //
  79. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
  80. # define BOOST_HAS_DECLSPEC
  81. # define BOOST_SYMBOL_EXPORT __attribute__((__dllexport__))
  82. # define BOOST_SYMBOL_IMPORT __attribute__((__dllimport__))
  83. #else
  84. # define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default")))
  85. # define BOOST_SYMBOL_IMPORT
  86. #endif
  87. #define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
  88. //
  89. // The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
  90. // between switch labels.
  91. //
  92. #if __cplusplus >= 201103L && defined(__has_warning)
  93. # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
  94. # define BOOST_FALLTHROUGH [[clang::fallthrough]]
  95. # endif
  96. #endif
  97. #if !__has_feature(cxx_auto_type)
  98. # define BOOST_NO_CXX11_AUTO_DECLARATIONS
  99. # define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS
  100. #endif
  101. //
  102. // Currently clang on Windows using VC++ RTL does not support C++11's char16_t or char32_t
  103. //
  104. #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || !(defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
  105. # define BOOST_NO_CXX11_CHAR16_T
  106. # define BOOST_NO_CXX11_CHAR32_T
  107. #endif
  108. #if defined(_MSC_VER) && (_MSC_VER >= 1800) && !defined(__GNUC__)
  109. #define BOOST_HAS_EXPM1
  110. #define BOOST_HAS_LOG1P
  111. #endif
  112. #if !__has_feature(cxx_constexpr)
  113. # define BOOST_NO_CXX11_CONSTEXPR
  114. #endif
  115. #if !__has_feature(cxx_decltype)
  116. # define BOOST_NO_CXX11_DECLTYPE
  117. #endif
  118. #if !__has_feature(cxx_decltype_incomplete_return_types)
  119. # define BOOST_NO_CXX11_DECLTYPE_N3276
  120. #endif
  121. #if !__has_feature(cxx_defaulted_functions)
  122. # define BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
  123. #endif
  124. #if !__has_feature(cxx_deleted_functions)
  125. # define BOOST_NO_CXX11_DELETED_FUNCTIONS
  126. #endif
  127. #if !__has_feature(cxx_explicit_conversions)
  128. # define BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  129. #endif
  130. #if !__has_feature(cxx_default_function_template_args)
  131. # define BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS
  132. #endif
  133. #if !__has_feature(cxx_generalized_initializers)
  134. # define BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  135. #endif
  136. #if !__has_feature(cxx_lambdas)
  137. # define BOOST_NO_CXX11_LAMBDAS
  138. #endif
  139. #if !__has_feature(cxx_local_type_template_args)
  140. # define BOOST_NO_CXX11_LOCAL_CLASS_TEMPLATE_PARAMETERS
  141. #endif
  142. #if !__has_feature(cxx_noexcept)
  143. # define BOOST_NO_CXX11_NOEXCEPT
  144. #endif
  145. #if !__has_feature(cxx_nullptr)
  146. # define BOOST_NO_CXX11_NULLPTR
  147. #endif
  148. #if !__has_feature(cxx_range_for)
  149. # define BOOST_NO_CXX11_RANGE_BASED_FOR
  150. #endif
  151. #if !__has_feature(cxx_raw_string_literals)
  152. # define BOOST_NO_CXX11_RAW_LITERALS
  153. #endif
  154. #if !__has_feature(cxx_reference_qualified_functions)
  155. # define BOOST_NO_CXX11_REF_QUALIFIERS
  156. #endif
  157. #if !__has_feature(cxx_generalized_initializers)
  158. # define BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  159. #endif
  160. #if !__has_feature(cxx_rvalue_references)
  161. # define BOOST_NO_CXX11_RVALUE_REFERENCES
  162. #endif
  163. #if !__has_feature(cxx_strong_enums)
  164. # define BOOST_NO_CXX11_SCOPED_ENUMS
  165. #endif
  166. #if !__has_feature(cxx_static_assert)
  167. # define BOOST_NO_CXX11_STATIC_ASSERT
  168. #endif
  169. #if !__has_feature(cxx_alias_templates)
  170. # define BOOST_NO_CXX11_TEMPLATE_ALIASES
  171. #endif
  172. #if !__has_feature(cxx_unicode_literals)
  173. # define BOOST_NO_CXX11_UNICODE_LITERALS
  174. #endif
  175. #if !__has_feature(cxx_variadic_templates)
  176. # define BOOST_NO_CXX11_VARIADIC_TEMPLATES
  177. #endif
  178. #if !__has_feature(cxx_user_literals)
  179. # define BOOST_NO_CXX11_USER_DEFINED_LITERALS
  180. #endif
  181. #if !__has_feature(cxx_alignas)
  182. # define BOOST_NO_CXX11_ALIGNAS
  183. #endif
  184. #if !__has_feature(cxx_trailing_return)
  185. # define BOOST_NO_CXX11_TRAILING_RESULT_TYPES
  186. #endif
  187. #if !__has_feature(cxx_inline_namespaces)
  188. # define BOOST_NO_CXX11_INLINE_NAMESPACES
  189. #endif
  190. #if !__has_feature(cxx_override_control)
  191. # define BOOST_NO_CXX11_FINAL
  192. #endif
  193. #if !(__has_feature(__cxx_binary_literals__) || __has_extension(__cxx_binary_literals__))
  194. # define BOOST_NO_CXX14_BINARY_LITERALS
  195. #endif
  196. #if !__has_feature(__cxx_decltype_auto__)
  197. # define BOOST_NO_CXX14_DECLTYPE_AUTO
  198. #endif
  199. #if !__has_feature(__cxx_aggregate_nsdmi__)
  200. # define BOOST_NO_CXX14_AGGREGATE_NSDMI
  201. #endif
  202. #if !__has_feature(__cxx_init_captures__)
  203. # define BOOST_NO_CXX14_INITIALIZED_LAMBDA_CAPTURES
  204. #endif
  205. #if !__has_feature(__cxx_generic_lambdas__)
  206. # define BOOST_NO_CXX14_GENERIC_LAMBDAS
  207. #endif
  208. // clang < 3.5 has a defect with dependent type, like following.
  209. //
  210. // template <class T>
  211. // constexpr typename enable_if<pred<T> >::type foo(T &)
  212. // { } // error: no return statement in constexpr function
  213. //
  214. // This issue also affects C++11 mode, but C++11 constexpr requires return stmt.
  215. // Therefore we don't care such case.
  216. //
  217. // Note that we can't check Clang version directly as the numbering system changes depending who's
  218. // creating the Clang release (see https://github.com/boostorg/config/pull/39#issuecomment-59927873)
  219. // so instead verify that we have a feature that was introduced at the same time as working C++14
  220. // constexpr (generic lambda's in this case):
  221. //
  222. #if !__has_feature(__cxx_generic_lambdas__) || !__has_feature(__cxx_relaxed_constexpr__)
  223. # define BOOST_NO_CXX14_CONSTEXPR
  224. #endif
  225. #if !__has_feature(__cxx_return_type_deduction__)
  226. # define BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION
  227. #endif
  228. #if !__has_feature(__cxx_variable_templates__)
  229. # define BOOST_NO_CXX14_VARIABLE_TEMPLATES
  230. #endif
  231. #if !defined(__cpp_structured_bindings) || (__cpp_structured_bindings < 201606)
  232. # define BOOST_NO_CXX17_STRUCTURED_BINDINGS
  233. #endif
  234. #if !defined(__cpp_if_constexpr) || (__cpp_if_constexpr < 201606)
  235. # define BOOST_NO_CXX17_IF_CONSTEXPR
  236. #endif
  237. // Clang 3.9+ in c++1z
  238. #if !__has_cpp_attribute(fallthrough) || __cplusplus < 201406L
  239. # define BOOST_NO_CXX17_INLINE_VARIABLES
  240. # define BOOST_NO_CXX17_FOLD_EXPRESSIONS
  241. #endif
  242. #if __cplusplus < 201103L
  243. #define BOOST_NO_CXX11_SFINAE_EXPR
  244. #endif
  245. #if __cplusplus < 201400
  246. // All versions with __cplusplus above this value seem to support this:
  247. # define BOOST_NO_CXX14_DIGIT_SEPARATORS
  248. #endif
  249. //
  250. // __builtin_unreachable:
  251. #if defined(__has_builtin) && __has_builtin(__builtin_unreachable)
  252. #define BOOST_UNREACHABLE_RETURN(x) __builtin_unreachable();
  253. #endif
  254. #if (__clang_major__ == 3) && (__clang_minor__ == 0)
  255. // Apparently a clang bug:
  256. # define BOOST_NO_CXX11_FIXED_LENGTH_VARIADIC_TEMPLATE_EXPANSION_PACKS
  257. #endif
  258. // Clang has supported the 'unused' attribute since the first release.
  259. #define BOOST_ATTRIBUTE_UNUSED __attribute__((__unused__))
  260. // Type aliasing hint.
  261. #if __has_attribute(__may_alias__)
  262. # define BOOST_MAY_ALIAS __attribute__((__may_alias__))
  263. #endif
  264. #ifndef BOOST_COMPILER
  265. # define BOOST_COMPILER "Clang version " __clang_version__
  266. #endif
  267. // Macro used to identify the Clang compiler.
  268. #define BOOST_CLANG 1