C++/NDK backends reorder nested type decls.
In the following example, C is declared before B.
parcelabe A {
parcelabe B {
C c;
}
parcelable C {}
}
Otherwise, C++ compiler will complain about undefined symbols.
Still we can't define nested types with cyclic references because decl
order is not determined for C++/NDK backends.
Bug: 201376182
Test: golden_test.sh check
Test: aidl_unittests
Change-Id: I8340dc33e3f745aa51dca038af0ad55893c3aa05
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 15bdfab..387941c 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -1056,6 +1056,13 @@
}
}
+ if (!TopologicalVisit(GetNestedTypes(), [](auto&) {})) {
+ AIDL_ERROR(this) << GetName()
+ << " has nested types with cyclic references. C++ and NDK backends don't "
+ "support cyclic references.";
+ return false;
+ }
+
for (const auto& v : GetFields()) {
const bool field_valid = v->CheckValid(typenames);
success = success && field_valid;