Add compile-time tests for RTTI to port_def.inc

This eliminates an ODR violation where users compile and install
Protobuf's C++ runtime without RTTI but do not define
GOOGLE_PROTOBUF_NO_RTTI when compiling their project with
the generated code.
pull/7269/head
Yannic 5 years ago committed by Adam Cozzette
parent 6f129c123e
commit 8a5a242364
  1. 9
      src/google/protobuf/port_def.inc

@ -308,6 +308,15 @@
#if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI
#define PROTOBUF_RTTI 0
#elif defined(__has_feature)
// https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
#define PROTOBUF_RTTI __has_feature(cxx_rtti)
#elif !defined(__cxx_rtti) && __cplusplus >= 199711L
// https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros#C.2B.2B98
#define PROTOBUF_RTTI 0
#elif defined(defined(__GNUC__)) && !defined(__GXX_RTTI)
# https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
#define PROTOBUF_RTTI 0
#else
#define PROTOBUF_RTTI 1
#endif

Loading…
Cancel
Save