Crypto++ 8.4 Free C++ class library of cryptographic schemes

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