From bfeb4ed5a46330db9bff7b02a6594ab0c206d56c Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 11 Aug 2020 10:53:26 -0700 Subject: [PATCH] Fix RTTI check in EncodableValue (flutter/engine#20398) __has_feature(cxx_rtti) is a clang extension, but clients of this code are mostly using the VS toolchain. This makes the RTTI check work with more compilers. --- .../include/flutter/encodable_value.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h index 91ac03d547..0b021292d0 100644 --- a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h +++ b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h @@ -14,6 +14,23 @@ #include #include +// Unless overridden, attempt to detect the RTTI state from the compiler. +#ifndef FLUTTER_ENABLE_RTTI +#if defined(_MSC_VER) +#ifdef _CPPRTTI +#define FLUTTER_ENABLE_RTTI 1 +#endif +#elif defined(__clang__) +#if __has_feature(cxx_rtti) +#define FLUTTER_ENABLE_RTTI 1 +#endif +#elif defined(__GNUC__) +#ifdef __GXX_RTTI +#define FLUTTER_ENABLE_RTTI 1 +#endif +#endif +#endif // #ifndef FLUTTER_ENABLE_RTTI + namespace flutter { static_assert(sizeof(double) == 8, "EncodableValue requires a 64-bit double"); @@ -56,7 +73,7 @@ class CustomEncodableValue { operator std::any &() { return value_; } operator const std::any &() const { return value_; } -#if __has_feature(cxx_rtti) +#if defined(FLUTTER_ENABLE_RTTI) && FLUTTER_ENABLE_RTTI // Passthrough to std::any's type(). const std::type_info& type() const noexcept { return value_.type(); } #endif