An enum is initialized as zero if it doesn't have default value am: f2e752316b
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/tools/aidl/+/15905949
Change-Id: I3f5c81730433c0e3fd2ed325e7762a25425db416
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index cc25657..bbee9b3 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -1111,6 +1111,13 @@
if (variable->GetDefaultValue()) {
out << " = " << cppType.c_str() << "(" << variable->ValueString(ConstantValueDecorator)
<< ")";
+ } else if (auto type = typenames.TryGetDefinedType(variable->GetType().GetName()); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << cppType << "(0)";
+ }
+ }
}
out << ";\n";
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index 274d283..0efd7eb 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -879,6 +879,13 @@
out << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << " " << variable->GetName();
if (variable->GetDefaultValue()) {
out << " = " << variable->ValueString(ConstantValueDecorator);
+ } else if (auto type = types.TryGetDefinedType(variable->GetType().GetName()); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << "(0)";
+ }
+ }
}
out << ";\n";
}