Export of internal Abseil changes
-- 803abc2dcad8b2354c988e9bf58dac4a17683832 by Gennadiy Rozental <rogeeff@google.com>: Avoid warning when RTTI is not enabled. PiperOrigin-RevId: 294247546 -- 5a7b0b4d07d1d6e56fbb0b0ffbf4f8fcab772dbf by Derek Mauro <dmauro@google.com>: Add a public Abseil FAQ PiperOrigin-RevId: 294226960 -- 6945c4a6df7d7679711fea31aacf4fba6ac7baa1 by Gennadiy Rozental <rogeeff@google.com>: Re-enable type mismatch check, which works in all the cases including shared libraries. We will use RTTI in case when our hand written approximation of it reports a type mismatch. This way we can ensure that if a flag is defined in one shared object and referenced in another we do not report spurious errors. PiperOrigin-RevId: 293905563 GitOrigin-RevId: 803abc2dcad8b2354c988e9bf58dac4a17683832 Change-Id: I1a23776d227ed2734c2e7183323786b7a95c3cc7
This commit is contained in:
parent
d95d156716
commit
bf78e97730
9 changed files with 229 additions and 71 deletions
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/macros.h"
|
||||
#include "absl/flags/config.h"
|
||||
#include "absl/flags/marshalling.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
|
|
@ -41,7 +43,10 @@ enum FlagOp {
|
|||
kCopyConstruct,
|
||||
kSizeof,
|
||||
kParse,
|
||||
kUnparse
|
||||
kUnparse,
|
||||
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
|
||||
kRuntimeTypeId
|
||||
#endif
|
||||
};
|
||||
using FlagOpFn = void* (*)(FlagOp, const void*, void*);
|
||||
using FlagMarshallingOpFn = void* (*)(FlagOp, const void*, void*, void*);
|
||||
|
|
@ -84,6 +89,11 @@ void* FlagOps(FlagOp op, const void* v1, void* v2) {
|
|||
return nullptr;
|
||||
case kSizeof:
|
||||
return reinterpret_cast<void*>(sizeof(T));
|
||||
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
|
||||
case kRuntimeTypeId:
|
||||
return const_cast<std::type_info*>(&typeid(T));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -146,6 +156,13 @@ inline size_t Sizeof(FlagOpFn op) {
|
|||
op(flags_internal::kSizeof, nullptr, nullptr)));
|
||||
}
|
||||
|
||||
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
|
||||
inline const std::type_info& RuntimeTypeId(FlagOpFn op) {
|
||||
return *static_cast<const std::type_info*>(
|
||||
op(flags_internal::kRuntimeTypeId, nullptr, nullptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle to FlagState objects. Specific flag state objects will restore state
|
||||
// of a flag produced this flag state from method CommandLineFlag::SaveState().
|
||||
class FlagStateInterface {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue