4646#include < iterator>
4747#include < memory>
4848
49+ #if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT)
50+ #include < unistd.h>
51+ #endif
52+
4953#ifdef _STLPORT_VERSION
5054 #define FLATBUFFERS_CPP98_STL
5155#endif
52- #ifndef FLATBUFFERS_CPP98_STL
53- #include < functional>
54- #endif
5556
56- #include " flatbuffers/stl_emulation.h"
57+ #ifdef __ANDROID__
58+ #include < android/api-level.h>
59+ #endif
5760
5861#if defined(__ICCARM__)
5962#include < intrinsics.h>
139142 #endif
140143#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
141144
142- #define FLATBUFFERS_VERSION_MAJOR 1
143- #define FLATBUFFERS_VERSION_MINOR 12
145+ #define FLATBUFFERS_VERSION_MAJOR 2
146+ #define FLATBUFFERS_VERSION_MINOR 0
144147#define FLATBUFFERS_VERSION_REVISION 0
145148#define FLATBUFFERS_STRING_EXPAND (X ) #X
146149#define FLATBUFFERS_STRING (X ) FLATBUFFERS_STRING_EXPAND(X)
@@ -154,24 +157,29 @@ namespace flatbuffers {
154157 defined (__clang__)
155158 #define FLATBUFFERS_FINAL_CLASS final
156159 #define FLATBUFFERS_OVERRIDE override
160+ #define FLATBUFFERS_EXPLICIT_CPP11 explicit
157161 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
158162#else
159163 #define FLATBUFFERS_FINAL_CLASS
160164 #define FLATBUFFERS_OVERRIDE
165+ #define FLATBUFFERS_EXPLICIT_CPP11
161166 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE
162167#endif
163168
164169#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
165170 (!defined (__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406 )) || \
166171 (defined (__cpp_constexpr) && __cpp_constexpr >= 200704 )
167172 #define FLATBUFFERS_CONSTEXPR constexpr
173+ #define FLATBUFFERS_CONSTEXPR_CPP11 constexpr
174+ #define FLATBUFFERS_CONSTEXPR_DEFINED
168175#else
169176 #define FLATBUFFERS_CONSTEXPR const
177+ #define FLATBUFFERS_CONSTEXPR_CPP11
170178#endif
171179
172180#if (defined(__cplusplus) && __cplusplus >= 201402L) || \
173181 (defined (__cpp_constexpr) && __cpp_constexpr >= 201304 )
174- #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR
182+ #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR_CPP11
175183#else
176184 #define FLATBUFFERS_CONSTEXPR_CPP14
177185#endif
@@ -189,9 +197,25 @@ namespace flatbuffers {
189197#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
190198 (!defined (__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404 )) || \
191199 defined (__clang__)
192- #define FLATBUFFERS_DELETE_FUNC (func) func = delete;
200+ #define FLATBUFFERS_DELETE_FUNC (func) func = delete
193201#else
194- #define FLATBUFFERS_DELETE_FUNC (func ) private: func;
202+ #define FLATBUFFERS_DELETE_FUNC (func ) private: func
203+ #endif
204+
205+ #if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
206+ (!defined (__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 409 )) || \
207+ defined (__clang__)
208+ #define FLATBUFFERS_DEFAULT_DECLARATION
209+ #endif
210+
211+ // Check if we can use template aliases
212+ // Not possible if Microsoft Compiler before 2012
213+ // Possible is the language feature __cpp_alias_templates is defined well
214+ // Or possible if the C++ std is C+11 or newer
215+ #if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */ ) \
216+ || (defined (__cpp_alias_templates) && __cpp_alias_templates >= 200704 ) \
217+ || (defined (__cplusplus) && __cplusplus >= 201103L )
218+ #define FLATBUFFERS_TEMPLATES_ALIASES
195219#endif
196220
197221#ifndef FLATBUFFERS_HAS_STRING_VIEW
@@ -236,10 +260,8 @@ namespace flatbuffers {
236260
237261#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
238262 // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
239- // They are part of the POSIX-2008 but not part of the C/C++ standard.
240- // GCC/Clang have definition (_XOPEN_SOURCE>=700) if POSIX-2008.
241263 #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
242- (defined (_XOPEN_SOURCE ) && (_XOPEN_SOURCE >=700 )))
264+ (defined (_XOPEN_VERSION ) && (_XOPEN_VERSION >=700 )) && (! defined (__ANDROID_API__) || ( defined (__ANDROID_API__) && (__ANDROID_API__>= 21 ) )))
243265 #define FLATBUFFERS_LOCALE_INDEPENDENT 1
244266 #else
245267 #define FLATBUFFERS_LOCALE_INDEPENDENT 0
@@ -308,7 +330,13 @@ typedef uintmax_t largest_scalar_t;
308330// We support aligning the contents of buffers up to this size.
309331#define FLATBUFFERS_MAX_ALIGNMENT 16
310332
333+ inline bool VerifyAlignmentRequirements (size_t align, size_t min_align = 1 ) {
334+ return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) &&
335+ (align & (align - 1 )) == 0 ; // must be power of 2
336+ }
337+
311338#if defined(_MSC_VER)
339+ #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized
312340 #pragma warning(push)
313341 #pragma warning(disable: 4127) // C4127: conditional expression is constant
314342#endif
@@ -374,6 +402,13 @@ T ReadScalar(const void *p) {
374402 return EndianScalar (*reinterpret_cast <const T *>(p));
375403}
376404
405+ // See https://github.com/google/flatbuffers/issues/5950
406+
407+ #if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
408+ #pragma GCC diagnostic push
409+ #pragma GCC diagnostic ignored "-Wstringop-overflow"
410+ #endif
411+
377412template <typename T>
378413// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
379414__supress_ubsan__ (" alignment" )
@@ -386,6 +421,10 @@ template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Of
386421 *reinterpret_cast <uoffset_t *>(p) = EndianScalar (t.o );
387422}
388423
424+ #if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
425+ #pragma GCC diagnostic pop
426+ #endif
427+
389428// Computes how many bytes you'd have to pad to be able to write an
390429// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
391430// memory).
0 commit comments