[fidlc] Allow empty tables
Test: make tools -j12 HOST_USE_ASAN=true && ./build-x64/host_tests/fidl-compiler-test
Change-Id: Ic1d807524f6d220026addc0782197e72e6224d1f
diff --git a/system/host/fidl/lib/parser.cpp b/system/host/fidl/lib/parser.cpp
index 6a19935..e33e052 100644
--- a/system/host/fidl/lib/parser.cpp
+++ b/system/host/fidl/lib/parser.cpp
@@ -952,9 +952,6 @@
if (!Ok())
Fail();
- if (members.empty())
- return Fail("Tables must have at least one member");
-
return std::make_unique<raw::TableDeclaration>(scope.GetSourceElement(),
std::move(attributes), std::move(identifier),
std::move(members));
diff --git a/system/utest/fidl-compiler/max_bytes_tests.cpp b/system/utest/fidl-compiler/max_bytes_tests.cpp
index 3c0003ef..3bee8e5 100644
--- a/system/utest/fidl-compiler/max_bytes_tests.cpp
+++ b/system/utest/fidl-compiler/max_bytes_tests.cpp
@@ -88,6 +88,9 @@
array<int64>:5 a;
};
+table TableWithNoMembers {
+};
+
table TableWithOneBool {
1: bool b;
};
@@ -258,6 +261,11 @@
MaxBytesLibrary test_library;
EXPECT_TRUE(test_library.Compile());
+ auto no_members = test_library.LookupTable("TableWithNoMembers");
+ EXPECT_NONNULL(no_members);
+ EXPECT_EQ(no_members->typeshape.Size(), 16);
+ EXPECT_EQ(no_members->typeshape.MaxOutOfLine(), 0);
+
auto one_bool = test_library.LookupTable("TableWithOneBool");
EXPECT_NONNULL(one_bool);
EXPECT_EQ(one_bool->typeshape.Size(), 16);
diff --git a/system/utest/fidl-compiler/max_handle_tests.cpp b/system/utest/fidl-compiler/max_handle_tests.cpp
index 571b210..93498cc 100644
--- a/system/utest/fidl-compiler/max_handle_tests.cpp
+++ b/system/utest/fidl-compiler/max_handle_tests.cpp
@@ -55,6 +55,9 @@
vector<TableWithOneHandle>:8 sv;
};
+table TableWithNoMembers {
+};
+
table TableWithOneBool {
1: bool b;
};
@@ -130,6 +133,10 @@
MaxHandlesLibrary test_library;
EXPECT_TRUE(test_library.Compile());
+ auto no_members = test_library.LookupTable("TableWithNoMembers");
+ EXPECT_NONNULL(no_members);
+ EXPECT_EQ(no_members->typeshape.MaxHandles(), 0);
+
auto one_bool = test_library.LookupTable("TableWithOneBool");
EXPECT_NONNULL(one_bool);
EXPECT_EQ(one_bool->typeshape.MaxHandles(), 0);
diff --git a/system/utest/fidl-compiler/table_tests.cpp b/system/utest/fidl-compiler/table_tests.cpp
index 9484f89..eed873c 100644
--- a/system/utest/fidl-compiler/table_tests.cpp
+++ b/system/utest/fidl-compiler/table_tests.cpp
@@ -99,8 +99,8 @@
};
)FIDL"));
- // Empty tables not allowed.
- EXPECT_FALSE(Compiles(R"FIDL(
+ // Empty tables are allowed.
+ EXPECT_TRUE(Compiles(R"FIDL(
library fidl.test.tables;
table Foo {