mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 02:01:38 +00:00
Audit and fixups for GCC and Clang (#7212)
Added (for compiler versions that support it): -Wmissing-declarations -Wzero-as-null-pointer-constant Then, fixes to problems identified by the extra warnings Tested only on GCC 9.4.0 Adjusted the CPP code generator to output nullptr where appropriate, to satisfy -Wzero-as-null-pointer-constant Added a lot of 'static' declarations in front of functions, to satisfy -Wmissing-declarations, and wrap static function defs in anonymous namespaces. There are advantages to both anonymous namespaces and static, it seems that marking a function as static will not publish the name in the symbol table at all, thus giving the linker less work to do.
This commit is contained in:
@@ -24,19 +24,21 @@
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
void ForAllEnums(
|
||||
namespace {
|
||||
|
||||
static void ForAllEnums(
|
||||
const flatbuffers::Vector<flatbuffers::Offset<reflection::Enum>> *enums,
|
||||
std::function<void(const reflection::Enum *)> func) {
|
||||
for (auto it = enums->cbegin(); it != enums->cend(); ++it) { func(*it); }
|
||||
}
|
||||
|
||||
void ForAllObjects(
|
||||
static void ForAllObjects(
|
||||
const flatbuffers::Vector<flatbuffers::Offset<reflection::Object>> *objects,
|
||||
std::function<void(const reflection::Object *)> func) {
|
||||
for (auto it = objects->cbegin(); it != objects->cend(); ++it) { func(*it); }
|
||||
}
|
||||
|
||||
void ForAllEnumValues(const reflection::Enum *enum_def,
|
||||
static void ForAllEnumValues(const reflection::Enum *enum_def,
|
||||
std::function<void(const reflection::EnumVal *)> func) {
|
||||
for (auto it = enum_def->values()->cbegin(); it != enum_def->values()->cend();
|
||||
++it) {
|
||||
@@ -44,7 +46,7 @@ void ForAllEnumValues(const reflection::Enum *enum_def,
|
||||
}
|
||||
}
|
||||
|
||||
void ForAllDocumentation(
|
||||
static void ForAllDocumentation(
|
||||
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>
|
||||
*documentation,
|
||||
std::function<void(const flatbuffers::String *)> func) {
|
||||
@@ -89,6 +91,8 @@ static bool IsVector(const reflection::BaseType base_type) {
|
||||
return base_type == reflection::Vector;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// A concrete base Flatbuffer Generator that specific language generators can
|
||||
// derive from.
|
||||
class BaseBfbsGenerator : public BfbsGenerator {
|
||||
@@ -187,4 +191,4 @@ class BaseBfbsGenerator : public BfbsGenerator {
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_BFBS_GEN_H_
|
||||
#endif // FLATBUFFERS_BFBS_GEN_H_
|
||||
|
||||
Reference in New Issue
Block a user