mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 07:51:38 +00:00
Fix std::span autodetection (#7805)
The current detection method fails on GCC 12.2 with -std=c++20 because the __cpp_lib_span macro is undefined. As per https://en.cppreference.com/w/cpp/utility/feature_test , __cpp_lib_span requires including either <version> or <span>. Since both these headers were added in C++20, checking for C++20 is sufficient (and simpler than using the library feature-test macro). Signed-off-by: Bernie Innocenti <bernie@codewiz.org> Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -41,15 +41,18 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The __cpp_lib_span is the predefined feature macro.
|
#ifndef FLATBUFFERS_USE_STD_SPAN
|
||||||
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
// Testing __cpp_lib_span requires including either <version> or <span>,
|
||||||
#include <span>
|
// both of which were added in C++20.
|
||||||
#elif defined(__cpp_lib_span) && defined(__has_include)
|
// See: https://en.cppreference.com/w/cpp/utility/feature_test
|
||||||
#if __has_include(<span>)
|
#if defined(__cplusplus) && __cplusplus >= 202002L
|
||||||
#include <array>
|
#define FLATBUFFERS_USE_STD_SPAN 1
|
||||||
#include <span>
|
|
||||||
#define FLATBUFFERS_USE_STD_SPAN
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif // FLATBUFFERS_USE_STD_SPAN
|
||||||
|
|
||||||
|
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
||||||
|
#include <array>
|
||||||
|
#include <span>
|
||||||
#else
|
#else
|
||||||
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
|
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
|
||||||
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
||||||
|
|||||||
Reference in New Issue
Block a user