Merge cherrypicks of [16010620, 16011373, 16011377, 16011394, 16011395, 16011396, 16011398, 16011400, 16011402, 16012407, 16010623, 16011574, 16011575, 16010923, 16011434, 16011691, 16011382, 16011383, 16011303, 16011385, 16011579] into security-aosp-rvc-release
Change-Id: Ie41ebee93f1f803801b07650f30f4c2b3e91d395
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";
}