An enum is initialized as zero if it doesn't have default value
In C++, NDK backend, an enum value hasn't been initialized if it doesn't
have default value. In that case, initialize an enum with zero for the
backends.
Bug: 198346478
Test: check golden output and m
Ignore-AOSP-First: security patch
Change-Id: I6cb67258cc4aacc41ae80c46ccee10a3cfe723f6
Merged-In: I6cb67258cc4aacc41ae80c46ccee10a3cfe723f6
(cherry picked from commit f39b16442ad832f2921ad0eec298b7c333936dc1)
(cherry picked from commit f2e752316b0d9d2708bc56d20c1649e704bca030)
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";