add -Wenum-zero warning.

This checks if enum types have 0 as its first enumerator.
For now, enum-type fields are initialized as 0 by default constructor.
To prevent invalid-valued enum-type fields, we recommend to set the
first enumerator as zero for enum types.

We could fix how default constructors initialize enum-type fields. But
this might break legacy codebase.

Bug: 168028537
Bug: 175841271
Test: aidl_unittests
Change-Id: Icb1d2949bb9fa2dd30e7620feffac1100f48114c
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 52aa085..be5b7ab 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -1259,6 +1259,18 @@
   for (const auto& enumerator : enumerators_) {
     success = success && enumerator->CheckValid(GetBackingType());
   }
+
+  AIDL_FATAL_IF(GetEnumerators().empty(), this)
+      << "The enum '" << GetName() << "' has no enumerators.";
+
+  const auto& first = GetEnumerators()[0];
+  if (auto first_value = first->ValueString(GetBackingType(), AidlConstantValueDecorator);
+      first_value != "0") {
+    diag.Report(first->GetLocation(), DiagnosticID::enum_zero)
+        << "The first enumerator '" << first->GetName() << "' should be 0, but it is "
+        << first_value << ".";
+  }
+
   return success;
 }