mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 13:08: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
@@ -1710,7 +1710,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// We need to add a trailing comma to all elements except the last one as
|
||||
// older versions of gcc complain about this.
|
||||
code_.SetValue("SEP", "");
|
||||
code_ += " enum {";
|
||||
code_ += " enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {";
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
const auto &field = **it;
|
||||
|
||||
Reference in New Issue
Block a user