clang.hpp 9.4 KB

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