mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 20:03:58 +00:00
make flatbuffers::IsFieldPresent safer (#4988)
Give the vtable offset enum inside each table the name "FlatBuffersVTableOffset" and base type voffset_t so it can be used as a dependent type in IsFieldPresent. This makes that function slightly safer since it prevents calling it with arbitrary, non-table types. Now, the only way to use IsFieldPresent incorrectly is to create your own type which does not inherit from flatbuffers::Table but has a dependent voffset convertible type "FlatBuffersVTableOffset".
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
55b30827f2
commit
ca417426c7
@@ -42,7 +42,7 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return TableInFirstNSTypeTable();
|
||||
}
|
||||
enum {
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_FOO_TABLE = 4,
|
||||
VT_FOO_ENUM = 6,
|
||||
VT_FOO_STRUCT = 8
|
||||
@@ -119,7 +119,7 @@ struct TableInC FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return TableInCTypeTable();
|
||||
}
|
||||
enum {
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_REFER_TO_A1 = 4,
|
||||
VT_REFER_TO_A2 = 6
|
||||
};
|
||||
@@ -184,7 +184,7 @@ struct SecondTableInA FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return SecondTableInATypeTable();
|
||||
}
|
||||
enum {
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_REFER_TO_C = 4
|
||||
};
|
||||
const NamespaceC::TableInC *refer_to_c() const {
|
||||
|
||||
Reference in New Issue
Block a user