Add --warnings-as-errors to flatc compiler. (#7034)

* Add --warnings-as-errors to flatc compiler.

With this option set, flatc will return an error on parsing if
any warnings occurred.

* Add unit test for opts.warnings_as_errors.

* Change explicit option setting to default.
This commit is contained in:
Jon Simantov
2022-01-25 17:01:16 -05:00
committed by GitHub
parent 9ef1524d3f
commit a2d38fbb98
4 changed files with 34 additions and 1 deletions

View File

@@ -2943,6 +2943,25 @@ void StructUnionTest() {
gadget.Set(fan);
}
void WarningsAsErrorsTest() {
{
flatbuffers::IDLOptions opts;
// opts.warnings_as_errors should default to false
flatbuffers::Parser parser(opts);
TEST_EQ(parser.Parse("table T { THIS_NAME_CAUSES_A_WARNING:string;}\n"
"root_type T;"),
true);
}
{
flatbuffers::IDLOptions opts;
opts.warnings_as_errors = true;
flatbuffers::Parser parser(opts);
TEST_EQ(parser.Parse("table T { THIS_NAME_CAUSES_A_WARNING:string;}\n"
"root_type T;"),
false);
}
}
void ConformTest() {
flatbuffers::Parser parser;
TEST_EQ(parser.Parse("table T { A:int; } enum E:byte { A }"), true);
@@ -4209,6 +4228,7 @@ int FlatBufferTests() {
FlatbuffersIteratorsTest();
FixedLengthArraySpanTest();
StructUnionTest();
WarningsAsErrorsTest();
return 0;
}