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:
Paul Harris
2022-08-17 01:48:41 +08:00
committed by GitHub
parent a66de58af9
commit f7c511957f
25 changed files with 327 additions and 140 deletions

View File

@@ -23,8 +23,9 @@
#include "idl_namer.h"
namespace flatbuffers {
namespace {
Namer::Config RustDefaultConfig() {
static Namer::Config RustDefaultConfig() {
// Historical note: We've been using "keep" casing since the original
// implementation, presumably because Flatbuffers schema style and Rust style
// roughly align. We are not going to enforce proper casing since its an
@@ -51,7 +52,7 @@ Namer::Config RustDefaultConfig() {
/*filename_extension=*/".rs" };
}
std::set<std::string> RustKeywords() {
static std::set<std::string> RustKeywords() {
return {
// https://doc.rust-lang.org/book/second-edition/appendix-01-keywords.html
"as",
@@ -173,7 +174,7 @@ enum FullType {
};
// Convert a Type to a FullType (exhaustive).
FullType GetFullType(const Type &type) {
static FullType GetFullType(const Type &type) {
// N.B. The order of these conditionals matters for some types.
if (IsString(type)) {
@@ -263,15 +264,16 @@ FullType GetFullType(const Type &type) {
return ftBool;
}
bool IsBitFlagsEnum(const EnumDef &enum_def) {
static bool IsBitFlagsEnum(const EnumDef &enum_def) {
return enum_def.attributes.Lookup("bit_flags") != nullptr;
}
// TableArgs make required non-scalars "Option<_>".
// TODO(cneo): Rework how we do defaults and stuff.
bool IsOptionalToBuilder(const FieldDef &field) {
static bool IsOptionalToBuilder(const FieldDef &field) {
return field.IsOptional() || !IsScalar(field.value.type.base_type);
}
} // namespace
bool GenerateRustModuleRootFile(const Parser &parser,
const std::string &output_dir) {