Skip to content

Commit

Permalink
Add compile-time tests for RTTI to port_def.inc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Yannic authored and acozzette committed Mar 10, 2020
1 parent 6f129c1 commit 8a5a242
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a5a242

Please sign in to comment.