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

@@ -29,6 +29,8 @@ namespace flatbuffers {
namespace kotlin {
namespace {
typedef std::map<std::string, std::pair<std::string, std::string> > FbbParamMap;
static TypedFloatConstantGenerator KotlinFloatGen("Double.", "Float.", "NaN",
"POSITIVE_INFINITY",
@@ -36,7 +38,7 @@ static TypedFloatConstantGenerator KotlinFloatGen("Double.", "Float.", "NaN",
static const CommentConfig comment_config = { "/**", " *", " */" };
static const std::string ident_pad = " ";
std::set<std::string> KotlinKeywords() {
static std::set<std::string> KotlinKeywords() {
return { "package", "as", "typealias", "class", "this", "super",
"val", "var", "fun", "for", "null", "true",
"false", "is", "in", "throw", "return", "break",
@@ -44,7 +46,7 @@ std::set<std::string> KotlinKeywords() {
"do", "when", "interface", "typeof", "Any", "Character" };
}
Namer::Config KotlinDefaultConfig() {
static Namer::Config KotlinDefaultConfig() {
return { /*types=*/Case::kKeep,
/*constants=*/Case::kKeep,
/*methods=*/Case::kLowerCamel,
@@ -66,6 +68,7 @@ Namer::Config KotlinDefaultConfig() {
/*filename_suffix=*/"",
/*filename_extension=*/".kt" };
}
} // namespace
class KotlinGenerator : public BaseGenerator {
public: