clang.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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_alignof)
  192. # define BOOST_NO_CXX11_ALIGNOF
  193. #endif
  194. #if !__has_feature(cxx_trailing_return)
  195. # define BOOST_NO_CXX11_TRAILING_RESULT_TYPES
  196. #endif
  197. #if !__has_feature(cxx_inline_namespaces)
  198. # define BOOST_NO_CXX11_INLINE_NAMESPACES
  199. #endif
  200. #if !__has_feature(cxx_override_control)
  201. # define BOOST_NO_CXX11_FINAL
  202. # define BOOST_NO_CXX11_OVERRIDE
  203. #endif
  204. #if !__has_feature(cxx_unrestricted_unions)
  205. # define BOOST_NO_CXX11_UNRESTRICTED_UNION
  206. #endif
  207. #if !(__has_feature(__cxx_binary_literals__) || __has_extension(__cxx_binary_literals__))
  208. # define BOOST_NO_CXX14_BINARY_LITERALS
  209. #endif
  210. #if !__has_feature(__cxx_decltype_auto__)
  211. # define BOOST_NO_CXX14_DECLTYPE_AUTO
  212. #endif
  213. #if !__has_feature(__cxx_aggregate_nsdmi__)
  214. # define BOOST_NO_CXX14_AGGREGATE_NSDMI
  215. #endif
  216. #if !__has_feature(__cxx_init_captures__)
  217. # define BOOST_NO_CXX14_INITIALIZED_LAMBDA_CAPTURES
  218. #endif
  219. #if !__has_feature(__cxx_generic_lambdas__)
  220. # define BOOST_NO_CXX14_GENERIC_LAMBDAS
  221. #endif
  222. // clang < 3.5 has a defect with dependent type, like following.
  223. //
  224. // template <class T>
  225. // constexpr typename enable_if<pred<T> >::type foo(T &)
  226. // { } // error: no return statement in constexpr function
  227. //
  228. // This issue also affects C++11 mode, but C++11 constexpr requires return stmt.
  229. // Therefore we don't care such case.
  230. //
  231. // Note that we can't check Clang version directly as the numbering system changes depending who's
  232. // creating the Clang release (see https://github.com/boostorg/config/pull/39#issuecomment-59927873)
  233. // so instead verify that we have a feature that was introduced at the same time as working C++14
  234. // constexpr (generic lambda's in this case):
  235. //
  236. #if !__has_feature(__cxx_generic_lambdas__) || !__has_feature(__cxx_relaxed_constexpr__)
  237. # define BOOST_NO_CXX14_CONSTEXPR
  238. #endif
  239. #if !__has_feature(__cxx_return_type_deduction__)
  240. # define BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION
  241. #endif
  242. #if !__has_feature(__cxx_variable_templates__)
  243. # define BOOST_NO_CXX14_VARIABLE_TEMPLATES
  244. #endif
  245. #if !defined(__cpp_structured_bindings) || (__cpp_structured_bindings < 201606)
  246. # define BOOST_NO_CXX17_STRUCTURED_BINDINGS
  247. #endif
  248. #if !defined(__cpp_if_constexpr) || (__cpp_if_constexpr < 201606)
  249. # define BOOST_NO_CXX17_IF_CONSTEXPR
  250. #endif
  251. // Clang 3.9+ in c++1z
  252. #if !__has_cpp_attribute(fallthrough) || __cplusplus < 201406L
  253. # define BOOST_NO_CXX17_INLINE_VARIABLES
  254. # define BOOST_NO_CXX17_FOLD_EXPRESSIONS
  255. #endif
  256. #if (__clang_major__ < 4) || (__cplusplus < 201406L) /* non-standard value that is greater than 201402, which is reported by clang 4.0.0 for C++1z */
  257. # define BOOST_NO_CXX17_AUTO_NONTYPE_TEMPLATE_PARAMS
  258. #endif
  259. #if __cplusplus < 201103L
  260. #define BOOST_NO_CXX11_SFINAE_EXPR
  261. #endif
  262. #if __cplusplus < 201400
  263. // All versions with __cplusplus above this value seem to support this:
  264. # define BOOST_NO_CXX14_DIGIT_SEPARATORS
  265. #endif
  266. // Unreachable code markup
  267. #if defined(__has_builtin)
  268. #if __has_builtin(__builtin_unreachable)
  269. #define BOOST_UNREACHABLE_RETURN(x) __builtin_unreachable();
  270. #endif
  271. #endif
  272. // Deprecated symbol markup
  273. #if __has_attribute(deprecated)
  274. #define BOOST_DEPRECATED(msg) __attribute__((deprecated(msg)))
  275. #endif
  276. #if (__clang_major__ == 3) && (__clang_minor__ == 0)
  277. // Apparently a clang bug:
  278. # define BOOST_NO_CXX11_FIXED_LENGTH_VARIADIC_TEMPLATE_EXPANSION_PACKS
  279. #endif
  280. // Clang has supported the 'unused' attribute since the first release.
  281. #define BOOST_ATTRIBUTE_UNUSED __attribute__((__unused__))
  282. // Type aliasing hint.
  283. #if __has_attribute(__may_alias__)
  284. # define BOOST_MAY_ALIAS __attribute__((__may_alias__))
  285. #endif
  286. #ifndef BOOST_COMPILER
  287. # define BOOST_COMPILER "Clang version " __clang_version__
  288. #endif
  289. // Macro used to identify the Clang compiler.
  290. #define BOOST_CLANG 1
  291. // BOOST_CLANG_VERSION
  292. #include <boost/config/compiler/clang_version.hpp>