config_cxx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // config_cxx.h - written and placed in public domain by Jeffrey Walton
  2. // the bits that make up this source file are from the
  3. // library's monolithic config.h.
  4. /// \file config_cxx.h
  5. /// \brief Library configuration file
  6. /// \details <tt>config_cxx.h</tt> provides defines for C++ language and
  7. /// runtime library
  8. /// features.
  9. /// \details <tt>config.h</tt> was split into components in May 2019 to better
  10. /// integrate with Autoconf and its feature tests. The splitting occurred so
  11. /// users could continue to include <tt>config.h</tt> while allowing Autoconf
  12. /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
  13. /// its feature tests.
  14. /// \note You should include <tt>config.h</tt> rather than <tt>config_cxx.h</tt>
  15. /// directly.
  16. /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,
  17. /// Make config.h more autoconf friendly</A>,
  18. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>
  19. /// on the Crypto++ wiki
  20. /// \since Crypto++ 8.3
  21. // Visual Studio began at VS2010, http://msdn.microsoft.com/en-us/library/hh567368%28v=vs.110%29.aspx
  22. // and https://docs.microsoft.com/en-us/cpp/visual-cpp-language-conformance
  23. // Intel, http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler
  24. // GCC, http://gcc.gnu.org/projects/cxx0x.html
  25. // Clang, http://clang.llvm.org/cxx_status.html
  26. #ifndef CRYPTOPP_CONFIG_CXX_H
  27. #define CRYPTOPP_CONFIG_CXX_H
  28. #include "config_os.h"
  29. #include "config_cpu.h"
  30. #include "config_ver.h"
  31. // https://github.com/weidai11/cryptopp/issues/960
  32. #include <string>
  33. #include <exception>
  34. // You may need to force include a C++ header on Android when using STLPort
  35. // to ensure _STLPORT_VERSION is defined
  36. #if (defined(CRYPTOPP_MSC_VERSION) && CRYPTOPP_MSC_VERSION <= 1300) || \
  37. defined(__MWERKS__) || \
  38. (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)) || \
  39. (__cplusplus >= 202002L))
  40. #define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
  41. #endif
  42. // Ancient Crypto++ define, dating back to C++98.
  43. #ifndef CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
  44. # define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 1
  45. # define CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION 1
  46. #endif
  47. // Compatibility with non-clang compilers.
  48. #ifndef __has_feature
  49. # define __has_feature(x) 0
  50. #endif
  51. // C++11 macro version, https://stackoverflow.com/q/7223991/608639
  52. #if ((CRYPTOPP_MSC_VERSION >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION)
  53. # define CRYPTOPP_CXX11 1
  54. #endif
  55. // Hack ahead. Apple's standard library does not have C++'s unique_ptr in C++11.
  56. // We can't test for unique_ptr directly because some of the non-Apple Clangs
  57. // on OS X fail the same way. However, modern standard libraries have
  58. // <forward_list>, so we test for it instead. Thanks to Jonathan Wakely for
  59. // devising the clever test for modern/ancient versions. TODO: test under
  60. // Xcode 3, where g++ is really g++.
  61. #if defined(__APPLE__) && defined(__clang__)
  62. # if !(defined(__has_include) && __has_include(<forward_list>))
  63. # undef CRYPTOPP_CXX11
  64. # endif
  65. #endif
  66. // C++14 macro version, https://stackoverflow.com/q/26089319/608639
  67. #if defined(CRYPTOPP_CXX11) && !defined(CRYPTOPP_NO_CXX14)
  68. # if ((CRYPTOPP_MSC_VERSION >= 1900) || (__cplusplus >= 201402L)) && !defined(_STLPORT_VERSION)
  69. # define CRYPTOPP_CXX14 1
  70. # endif
  71. #endif
  72. // C++17 macro version, https://stackoverflow.com/q/38456127/608639
  73. #if defined(CRYPTOPP_CXX14) && !defined(CRYPTOPP_NO_CXX17)
  74. # if ((CRYPTOPP_MSC_VERSION >= 1900) || (__cplusplus >= 201703L)) && !defined(_STLPORT_VERSION)
  75. # define CRYPTOPP_CXX17 1
  76. # endif
  77. #endif
  78. // ***************** C++11 and above ********************
  79. #if defined(CRYPTOPP_CXX11)
  80. // atomics: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.1/3.2; Intel 13.0; SunCC 5.14.
  81. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_atomic) || \
  82. (__INTEL_COMPILER >= 1300) || (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5140)
  83. # define CRYPTOPP_CXX11_ATOMIC 1
  84. #endif // atomics
  85. // synchronization: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.3; Xcode 5.0; Intel 12.0; SunCC 5.13.
  86. // TODO: verify Clang and Intel versions; find __has_feature(x) extension for Clang
  87. #if (CRYPTOPP_MSC_VERSION >= 1700) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || \
  88. (CRYPTOPP_APPLE_CLANG_VERSION >= 50000) || (__INTEL_COMPILER >= 1200) || \
  89. (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5130)
  90. // Hack ahead. New GCC compilers like GCC 6 on AIX 7.0 or earlier as well as original MinGW
  91. // don't have the synchronization gear. However, Wakely's test used for Apple does not work
  92. // on the GCC/AIX combination. Another twist is we need other stuff from C++11,
  93. // like no-except destructors. Dumping preprocessors shows the following may
  94. // apply: http://stackoverflow.com/q/14191566/608639.
  95. # include <cstddef>
  96. # if !defined(__GLIBCXX__) || defined(_GLIBCXX_HAS_GTHREADS)
  97. # define CRYPTOPP_CXX11_SYNCHRONIZATION 1
  98. # endif
  99. #endif // synchronization
  100. // Dynamic Initialization and Destruction with Concurrency ("Magic Statics")
  101. // MS at VS2015 with Vista (19.00); GCC at 4.3; LLVM Clang at 2.9; Apple Clang at 4.0; Intel 11.1; SunCC 5.13.
  102. // Microsoft's implementation only works for Vista and above, so its further
  103. // limited. http://connect.microsoft.com/VisualStudio/feedback/details/1789709
  104. // Clang may not support this as early as we indicate. Also see https://bugs.llvm.org/show_bug.cgi?id=47012.
  105. #if (__cpp_threadsafe_static_init >= 200806) || \
  106. (CRYPTOPP_MSC_VERSION >= 1900) && ((WINVER >= 0x0600) || (_WIN32_WINNT >= 0x0600)) || \
  107. (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || \
  108. (__INTEL_COMPILER >= 1110) || (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  109. # define CRYPTOPP_CXX11_STATIC_INIT 1
  110. #endif // Dynamic Initialization compilers
  111. // deleted functions: MS at VS2013 (18.00); GCC at 4.3; Clang at 2.9; Intel 12.1; SunCC 5.13.
  112. #if (CRYPTOPP_MSC_VERSION >= 1800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || \
  113. (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (__INTEL_COMPILER >= 1210) || \
  114. (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  115. # define CRYPTOPP_CXX11_DELETED_FUNCTIONS 1
  116. #endif // deleted functions
  117. // alignof/alignas: MS at VS2015 (19.00); GCC at 4.8; Clang at 3.0; Intel 15.0; SunCC 5.13.
  118. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_alignas) || \
  119. (__INTEL_COMPILER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40800) || (__SUNPRO_CC >= 0x5130)
  120. # define CRYPTOPP_CXX11_ALIGNAS 1
  121. #endif // alignas
  122. // alignof: MS at VS2015 (19.00); GCC at 4.5; Clang at 2.9; Intel 15.0; SunCC 5.13.
  123. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_alignof) || \
  124. (__INTEL_COMPILER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40500) || (__SUNPRO_CC >= 0x5130)
  125. # define CRYPTOPP_CXX11_ALIGNOF 1
  126. #endif // alignof
  127. // initializer lists: MS at VS2013 (18.00); GCC at 4.4; Clang at 3.1; Intel 14.0; SunCC 5.13.
  128. #if (CRYPTOPP_MSC_VERSION >= 1800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30100) || \
  129. (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (__INTEL_COMPILER >= 1400) || \
  130. (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5130)
  131. # define CRYPTOPP_CXX11_INITIALIZER_LIST 1
  132. #endif // alignas
  133. // lambdas: MS at VS2012 (17.00); GCC at 4.9; Clang at 3.3; Intel 12.0; SunCC 5.14.
  134. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_lambdas) || \
  135. (__INTEL_COMPILER >= 1200) || (CRYPTOPP_GCC_VERSION >= 40900) || (__SUNPRO_CC >= 0x5140)
  136. # define CRYPTOPP_CXX11_LAMBDA 1
  137. #endif // lambdas
  138. // noexcept: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.0; Intel 14.0; SunCC 5.13.
  139. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_noexcept) || \
  140. (__INTEL_COMPILER >= 1400) || (CRYPTOPP_GCC_VERSION >= 40600) || (__SUNPRO_CC >= 0x5130)
  141. # define CRYPTOPP_CXX11_NOEXCEPT 1
  142. #endif // noexcept compilers
  143. // variadic templates: MS at VS2013 (18.00); GCC at 4.3; Clang at 2.9; Intel 12.1; SunCC 5.13.
  144. #if (__cpp_variadic_templates >= 200704) || __has_feature(cxx_variadic_templates) || \
  145. (CRYPTOPP_MSC_VERSION >= 1800) || (__INTEL_COMPILER >= 1210) || \
  146. (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  147. # define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1
  148. #endif // variadic templates
  149. // constexpr: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.1; Intel 16.0; SunCC 5.13.
  150. // Intel has mis-supported the feature since at least ICPC 13.00
  151. #if (__cpp_constexpr >= 200704) || __has_feature(cxx_constexpr) || \
  152. (CRYPTOPP_MSC_VERSION >= 1900) || (__INTEL_COMPILER >= 1600) || \
  153. (CRYPTOPP_GCC_VERSION >= 40600) || (__SUNPRO_CC >= 0x5130)
  154. # define CRYPTOPP_CXX11_CONSTEXPR 1
  155. #endif // constexpr compilers
  156. // strong typed enums: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.3; Intel 14.0; SunCC 5.12.
  157. // Mircorosft and Intel had partial support earlier, but we require full support.
  158. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_strong_enums) || \
  159. (__INTEL_COMPILER >= 1400) || (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5120)
  160. # define CRYPTOPP_CXX11_STRONG_ENUM 1
  161. #endif // constexpr compilers
  162. // nullptr_t: MS at VS2010 (16.00); GCC at 4.6; Clang at 3.3; Intel 10.0; SunCC 5.13.
  163. #if (CRYPTOPP_MSC_VERSION >= 1600) || __has_feature(cxx_nullptr) || \
  164. (__INTEL_COMPILER >= 1000) || (CRYPTOPP_GCC_VERSION >= 40600) || \
  165. (__SUNPRO_CC >= 0x5130) || defined(__IBMCPP_NULLPTR)
  166. # define CRYPTOPP_CXX11_NULLPTR 1
  167. #endif // nullptr_t compilers
  168. #endif // CRYPTOPP_CXX11
  169. // ***************** C++14 and above ********************
  170. #if defined(CRYPTOPP_CXX14)
  171. // Extended static_assert with one argument
  172. // Microsoft cannot handle the single argument static_assert as of VS2019 (cl.exe 19.00)
  173. #if (__cpp_static_assert >= 201411)
  174. # define CRYPTOPP_CXX17_STATIC_ASSERT 1
  175. #endif // static_assert
  176. #endif
  177. // ***************** C++17 and above ********************
  178. // C++17 is available
  179. #if defined(CRYPTOPP_CXX17)
  180. // C++17 uncaught_exceptions: MS at VS2015 (19.00); GCC at 6.0; Clang at 3.5; Intel 18.0.
  181. // Clang and __EXCEPTIONS see http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html
  182. // Also see https://github.com/weidai11/cryptopp/issues/980. I'm not sure what
  183. // to do when the compiler defines __cpp_lib_uncaught_exceptions but the platform
  184. // does not support std::uncaught_exceptions. What was Apple thinking???
  185. #if defined(__clang__)
  186. # if __EXCEPTIONS && __has_feature(cxx_exceptions)
  187. # if __cpp_lib_uncaught_exceptions >= 201411L
  188. # define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1
  189. # endif
  190. # endif
  191. #elif (CRYPTOPP_MSC_VERSION >= 1900) || (__INTEL_COMPILER >= 1800) || \
  192. (CRYPTOPP_GCC_VERSION >= 60000) || (__cpp_lib_uncaught_exceptions >= 201411L)
  193. # define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1
  194. #endif // uncaught_exceptions compilers
  195. #endif // CRYPTOPP_CXX17
  196. // ***************** C++ fixups ********************
  197. #if defined(CRYPTOPP_CXX11_NOEXCEPT)
  198. # define CRYPTOPP_THROW noexcept(false)
  199. # define CRYPTOPP_NO_THROW noexcept(true)
  200. #else
  201. # define CRYPTOPP_THROW
  202. # define CRYPTOPP_NO_THROW
  203. #endif // CRYPTOPP_CXX11_NOEXCEPT
  204. // Hack... C++11 nullptr_t type safety and analysis
  205. #if defined(CRYPTOPP_CXX11_NULLPTR) && !defined(NULLPTR)
  206. # define NULLPTR nullptr
  207. #elif !defined(NULLPTR)
  208. # define NULLPTR NULL
  209. #endif // CRYPTOPP_CXX11_NULLPTR
  210. #endif // CRYPTOPP_CONFIG_CXX_H