diff --git a/dart/test/monster_test_my_game.example2_generated.dart b/dart/test/monster_test_my_game.example2_generated.dart index 11e51ab29..9a3ab6626 100644 --- a/dart/test/monster_test_my_game.example2_generated.dart +++ b/dart/test/monster_test_my_game.example2_generated.dart @@ -8,8 +8,8 @@ import 'package:flat_buffers/flat_buffers.dart' as fb; import 'include_test1_my_game.example2_generated.dart'; import 'include_test2_my_game.example2_generated.dart'; -import './monster_test_my_game.example_generated.dart' as my_game_example; import './monster_test_my_game_generated.dart' as my_game; +import './monster_test_my_game.example_generated.dart' as my_game_example; class Monster { Monster._(this._bc, this._bcOffset); diff --git a/dart/test/monster_test_my_game.example_generated.dart b/dart/test/monster_test_my_game.example_generated.dart index 5adb4f239..d243b2d48 100644 --- a/dart/test/monster_test_my_game.example_generated.dart +++ b/dart/test/monster_test_my_game.example_generated.dart @@ -8,8 +8,8 @@ import 'package:flat_buffers/flat_buffers.dart' as fb; import 'include_test1_my_game.example_generated.dart'; import 'include_test2_my_game.example_generated.dart'; -import './monster_test_my_game.example2_generated.dart' as my_game_example2; import './monster_test_my_game_generated.dart' as my_game; +import './monster_test_my_game.example2_generated.dart' as my_game_example2; class Color { final int value; diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 0eec35351..c4f7c8660 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1778,21 +1778,24 @@ CheckedError Parser::ParseDecl() { EXPECT('{'); while (token_ != '}') ECHECK(ParseField(*struct_def)); auto force_align = struct_def->attributes.Lookup("force_align"); - if (fixed && force_align) { - auto align = static_cast(atoi(force_align->constant.c_str())); - if (force_align->type.base_type != BASE_TYPE_INT || - align < struct_def->minalign || align > FLATBUFFERS_MAX_ALIGNMENT || - align & (align - 1)) - return Error( - "force_align must be a power of two integer ranging from the" - "struct\'s natural alignment to " + - NumToString(FLATBUFFERS_MAX_ALIGNMENT)); - struct_def->minalign = align; + if (fixed) { + if (force_align) { + auto align = static_cast(atoi(force_align->constant.c_str())); + if (force_align->type.base_type != BASE_TYPE_INT || + align < struct_def->minalign || align > FLATBUFFERS_MAX_ALIGNMENT || + align & (align - 1)) + return Error( + "force_align must be a power of two integer ranging from the" + "struct\'s natural alignment to " + + NumToString(FLATBUFFERS_MAX_ALIGNMENT)); + struct_def->minalign = align; + } + if (!struct_def->bytesize) return Error("size 0 structs not allowed"); } struct_def->PadLastField(struct_def->minalign); // Check if this is a table that has manual id assignments auto &fields = struct_def->fields.vec; - if (!struct_def->fixed && fields.size()) { + if (!fixed && fields.size()) { size_t num_id_fields = 0; for (auto it = fields.begin(); it != fields.end(); ++it) { if ((*it)->attributes.Lookup("id")) num_id_fields++; diff --git a/tests/include_test/sub/include_test2.fbs b/tests/include_test/sub/include_test2.fbs index 3257ffc14..7225735cb 100644 --- a/tests/include_test/sub/include_test2.fbs +++ b/tests/include_test/sub/include_test2.fbs @@ -5,7 +5,7 @@ namespace MyGame.OtherNameSpace; enum FromInclude:long { IncludeVal } -struct Unused {} +struct Unused { a:int; } table TableB { a:TableA; diff --git a/tests/javatest.bin b/tests/javatest.bin index 77835c736..15bea5fb8 100644 Binary files a/tests/javatest.bin and b/tests/javatest.bin differ diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index a6b87d4a4..f7bb462d9 100644 Binary files a/tests/monster_test.bfbs and b/tests/monster_test.bfbs differ diff --git a/tests/monster_test.schema.json b/tests/monster_test.schema.json index 09c716c05..b2df316aa 100644 --- a/tests/monster_test.schema.json +++ b/tests/monster_test.schema.json @@ -16,6 +16,7 @@ "MyGame_OtherNameSpace_Unused" : { "type" : "object", "properties" : { + "a" : { "type" : "number" } }, "additionalProperties" : false }, diff --git a/tests/test.cpp b/tests/test.cpp index 90c791736..d59160be0 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1230,6 +1230,7 @@ void ErrorTest() { TestError("enum X:byte (bit_flags) { Y=8 }", "bit flag out"); TestError("table X { Y:int; } table X {", "datatype already"); TestError("struct X (force_align: 7) { Y:int; }", "force_align"); + TestError("struct X {}", "size 0"); TestError("{}", "no root"); TestError("table X { Y:byte; } root_type X; { Y:1 } { Y:1 }", "end of file"); TestError("table X { Y:byte; } root_type X; { Y:1 } table Y{ Z:int }",