config_cxx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)))
  37. #define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
  38. #endif
  39. // Ancient Crypto++ define, dating back to C++98.
  40. #ifndef CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
  41. # define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 1
  42. # define CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION 1
  43. #endif
  44. // Compatibility with non-clang compilers.
  45. #ifndef __has_feature
  46. # define __has_feature(x) 0
  47. #endif
  48. // C++11 macro version, https://stackoverflow.com/q/7223991/608639
  49. #if ((_MSC_VER >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION)
  50. # define CRYPTOPP_CXX11 1
  51. #endif
  52. // Hack ahead. Apple's standard library does not have C++'s unique_ptr in C++11.
  53. // We can't test for unique_ptr directly because some of the non-Apple Clangs
  54. // on OS X fail the same way. However, modern standard libraries have
  55. // <forward_list>, so we test for it instead. Thanks to Jonathan Wakely for
  56. // devising the clever test for modern/ancient versions. TODO: test under
  57. // Xcode 3, where g++ is really g++.
  58. #if defined(__APPLE__) && defined(__clang__)
  59. # if !(defined(__has_include) && __has_include(<forward_list>))
  60. # undef CRYPTOPP_CXX11
  61. # endif
  62. #endif
  63. // C++14 macro version, https://stackoverflow.com/q/26089319/608639
  64. #if defined(CRYPTOPP_CXX11) && !defined(CRYPTOPP_NO_CXX14)
  65. # if ((_MSC_VER >= 1900) || (__cplusplus >= 201402L)) && !defined(_STLPORT_VERSION)
  66. # define CRYPTOPP_CXX14 1
  67. # endif
  68. #endif
  69. // C++17 macro version, https://stackoverflow.com/q/38456127/608639
  70. #if defined(CRYPTOPP_CXX14) && !defined(CRYPTOPP_NO_CXX17)
  71. # if ((_MSC_VER >= 1900) || (__cplusplus >= 201703L)) && !defined(_STLPORT_VERSION)
  72. # define CRYPTOPP_CXX17 1
  73. # endif
  74. #endif
  75. // ***************** C++11 and above ********************
  76. #if defined(CRYPTOPP_CXX11)
  77. // atomics: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.1/3.2; Intel 13.0; SunCC 5.14.
  78. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_atomic) || \
  79. (__INTEL_COMPILER >= 1300) || (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5140)
  80. # define CRYPTOPP_CXX11_ATOMIC 1
  81. #endif // atomics
  82. // synchronization: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.3; Xcode 5.0; Intel 12.0; SunCC 5.13.
  83. // TODO: verify Clang and Intel versions; find __has_feature(x) extension for Clang
  84. #if (CRYPTOPP_MSC_VERSION >= 1700) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || \
  85. (CRYPTOPP_APPLE_CLANG_VERSION >= 50000) || (__INTEL_COMPILER >= 1200) || \
  86. (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5130)
  87. // Hack ahead. New GCC compilers like GCC 6 on AIX 7.0 or earlier as well as original MinGW
  88. // don't have the synchronization gear. However, Wakely's test used for Apple does not work
  89. // on the GCC/AIX combination. Another twist is we need other stuff from C++11,
  90. // like no-except destructors. Dumping preprocessors shows the following may
  91. // apply: http://stackoverflow.com/q/14191566/608639.
  92. # include <cstddef>
  93. # if !defined(__GLIBCXX__) || defined(_GLIBCXX_HAS_GTHREADS)
  94. # define CRYPTOPP_CXX11_SYNCHRONIZATION 1
  95. # endif
  96. #endif // synchronization
  97. // Dynamic Initialization and Destruction with Concurrency ("Magic Statics")
  98. // 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.
  99. // Microsoft's implementation only works for Vista and above, so its further
  100. // limited. http://connect.microsoft.com/VisualStudio/feedback/details/1789709
  101. // Clang may not support this as early as we indicate. Also see https://bugs.llvm.org/show_bug.cgi?id=47012.
  102. #if (__cpp_threadsafe_static_init >= 200806) || \
  103. (CRYPTOPP_MSC_VERSION >= 1900) && ((WINVER >= 0x0600) || (_WIN32_WINNT >= 0x0600)) || \
  104. (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || \
  105. (__INTEL_COMPILER >= 1110) || (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  106. # define CRYPTOPP_CXX11_STATIC_INIT 1
  107. #endif // Dynamic Initialization compilers
  108. // deleted functions: MS at VS2013 (18.00); GCC at 4.3; Clang at 2.9; Intel 12.1; SunCC 5.13.
  109. #if (CRYPTOPP_MSC_VERSION >= 1800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || \
  110. (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (__INTEL_COMPILER >= 1210) || \
  111. (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  112. # define CRYPTOPP_CXX11_DELETED_FUNCTIONS 1
  113. #endif // deleted functions
  114. // alignof/alignas: MS at VS2015 (19.00); GCC at 4.8; Clang at 3.0; Intel 15.0; SunCC 5.13.
  115. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_alignas) || \
  116. (__INTEL_COMPILER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40800) || (__SUNPRO_CC >= 0x5130)
  117. # define CRYPTOPP_CXX11_ALIGNAS 1
  118. #endif // alignas
  119. // alignof: MS at VS2015 (19.00); GCC at 4.5; Clang at 2.9; Intel 15.0; SunCC 5.13.
  120. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_alignof) || \
  121. (__INTEL_COMPILER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40500) || (__SUNPRO_CC >= 0x5130)
  122. # define CRYPTOPP_CXX11_ALIGNOF 1
  123. #endif // alignof
  124. // initializer lists: MS at VS2013 (18.00); GCC at 4.4; Clang at 3.1; Intel 14.0; SunCC 5.13.
  125. #if (CRYPTOPP_MSC_VERSION >= 1800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30100) || \
  126. (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (__INTEL_COMPILER >= 1400) || \
  127. (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5130)
  128. # define CRYPTOPP_CXX11_INITIALIZER_LIST 1
  129. #endif // alignas
  130. // lambdas: MS at VS2012 (17.00); GCC at 4.9; Clang at 3.3; Intel 12.0; SunCC 5.14.
  131. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_lambdas) || \
  132. (__INTEL_COMPILER >= 1200) || (CRYPTOPP_GCC_VERSION >= 40900) || (__SUNPRO_CC >= 0x5140)
  133. # define CRYPTOPP_CXX11_LAMBDA 1
  134. #endif // lambdas
  135. // noexcept: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.0; Intel 14.0; SunCC 5.13.
  136. #if (CRYPTOPP_MSC_VERSION >= 1900) || __has_feature(cxx_noexcept) || \
  137. (__INTEL_COMPILER >= 1400) || (CRYPTOPP_GCC_VERSION >= 40600) || (__SUNPRO_CC >= 0x5130)
  138. # define CRYPTOPP_CXX11_NOEXCEPT 1
  139. #endif // noexcept compilers
  140. // variadic templates: MS at VS2013 (18.00); GCC at 4.3; Clang at 2.9; Intel 12.1; SunCC 5.13.
  141. #if (__cpp_variadic_templates >= 200704) || __has_feature(cxx_variadic_templates) || \
  142. (CRYPTOPP_MSC_VERSION >= 1800) || (__INTEL_COMPILER >= 1210) || \
  143. (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
  144. # define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1
  145. #endif // variadic templates
  146. // constexpr: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.1; Intel 16.0; SunCC 5.13.
  147. // Intel has mis-supported the feature since at least ICPC 13.00
  148. #if (__cpp_constexpr >= 200704) || __has_feature(cxx_constexpr) || \
  149. (CRYPTOPP_MSC_VERSION >= 1900) || (__INTEL_COMPILER >= 1600) || \
  150. (CRYPTOPP_GCC_VERSION >= 40600) || (__SUNPRO_CC >= 0x5130)
  151. # define CRYPTOPP_CXX11_CONSTEXPR 1
  152. #endif // constexpr compilers
  153. // strong typed enums: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.3; Intel 14.0; SunCC 5.12.
  154. // Mircorosft and Intel had partial support earlier, but we require full support.
  155. #if (CRYPTOPP_MSC_VERSION >= 1700) || __has_feature(cxx_strong_enums) || \
  156. (__INTEL_COMPILER >= 1400) || (CRYPTOPP_GCC_VERSION >= 40400) || (__SUNPRO_CC >= 0x5120)
  157. # define CRYPTOPP_CXX11_STRONG_ENUM 1
  158. #endif // constexpr compilers
  159. // nullptr_t: MS at VS2010 (16.00); GCC at 4.6; Clang at 3.3; Intel 10.0; SunCC 5.13.
  160. #if (CRYPTOPP_MSC_VERSION >= 1600) || __has_feature(cxx_nullptr) || \
  161. (__INTEL_COMPILER >= 1000) || (CRYPTOPP_GCC_VERSION >= 40600) || \
  162. (__SUNPRO_CC >= 0x5130) || defined(__IBMCPP_NULLPTR)
  163. # define CRYPTOPP_CXX11_NULLPTR 1
  164. #endif // nullptr_t compilers
  165. #endif // CRYPTOPP_CXX11
  166. // ***************** C++14 and above ********************
  167. #if defined(CRYPTOPP_CXX14)
  168. // Extended static_assert with one argument
  169. // Microsoft cannot handle the single argument static_assert as of VS2019 (cl.exe 19.00)
  170. #if (__cpp_static_assert >= 201411)
  171. # define CRYPTOPP_CXX17_STATIC_ASSERT 1
  172. #endif // static_assert
  173. #endif
  174. // ***************** C++17 and above ********************
  175. // C++17 is available
  176. #if defined(CRYPTOPP_CXX17)
  177. // C++17 uncaught_exceptions: MS at VS2015 (19.00); GCC at 6.0; Clang at 3.5; Intel 18.0.
  178. // Clang and __EXCEPTIONS see http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html
  179. // Also see https://github.com/weidai11/cryptopp/issues/980. I'm not sure what
  180. // to do when the compiler defines __cpp_lib_uncaught_exceptions but the platform
  181. // does not support std::uncaught_exceptions. What was Apple thinking???
  182. #if defined(__clang__)
  183. # if __EXCEPTIONS && __has_feature(cxx_exceptions)
  184. # if __cpp_lib_uncaught_exceptions >= 201411L
  185. # define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1
  186. # endif
  187. # endif
  188. #elif (CRYPTOPP_MSC_VERSION >= 1900) || (__INTEL_COMPILER >= 1800) || \
  189. (CRYPTOPP_GCC_VERSION >= 60000) || (__cpp_lib_uncaught_exceptions >= 201411L)
  190. # define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1
  191. #endif // uncaught_exceptions compilers
  192. #endif // CRYPTOPP_CXX17
  193. // ***************** C++ fixups ********************
  194. #if defined(CRYPTOPP_CXX11_NOEXCEPT)
  195. # define CRYPTOPP_THROW noexcept(false)
  196. # define CRYPTOPP_NO_THROW noexcept(true)
  197. #else
  198. # define CRYPTOPP_THROW
  199. # define CRYPTOPP_NO_THROW
  200. #endif // CRYPTOPP_CXX11_NOEXCEPT
  201. // Hack... C++11 nullptr_t type safety and analysis
  202. #if defined(CRYPTOPP_CXX11_NULLPTR) && !defined(NULLPTR)
  203. # define NULLPTR nullptr
  204. #elif !defined(NULLPTR)
  205. # define NULLPTR NULL
  206. #endif // CRYPTOPP_CXX11_NULLPTR
  207. #endif // CRYPTOPP_CONFIG_CXX_H