From c3e32935494798aa5b7b2a557b29275e21240b02 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Wed, 6 Sep 2023 17:58:59 -0700 Subject: [RESTRICT AUTOMERGE] Fix std::unique_ptr error with incomplete CommonFeatureGroup After upgrading libc++, Clang fails to compile DumpManifest.cpp. prebuilts/clang/host/linux-x86/clang-r498229/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'aapt::CommonFeatureGroup' static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type"); ^~~~~~~~~~~ Fix the problem by deferring the instantiation of ~unique_ptr, by making the ManifestExtractor constructor out-of-line and moving it and the initialization of commonFeatureGroup_ to a point after CommonFeatureGroup has been defined. Bug: b/175635923 Test: treehugger Change-Id: I9ab51f29724fded24773344aa36763ffeea02d00 Merged-In: I9ab51f29724fded24773344aa36763ffeea02d00 --- tools/aapt2/dump/DumpManifest.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp index 9828b97982ed..f93949bab341 100644 --- a/tools/aapt2/dump/DumpManifest.cpp +++ b/tools/aapt2/dump/DumpManifest.cpp @@ -116,9 +116,7 @@ class CommonFeatureGroup; class ManifestExtractor { public: - - explicit ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options) - : apk_(apk), options_(options) { } + explicit ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options); class Element { public: @@ -387,7 +385,7 @@ class ManifestExtractor { DumpManifestOptions& options_; private: - std::unique_ptr commonFeatureGroup_ = util::make_unique(); + std::unique_ptr commonFeatureGroup_; std::map locales_; std::map densities_; std::vector parent_stack_; @@ -1970,6 +1968,12 @@ static void Print(ManifestExtractor::Element* el, text::Printer* printer) { } } +// Define this constructor after the CommonFeatureGroup class definition to avoid errors with using +// std::unique_ptr on an incomplete type. +ManifestExtractor::ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options) + : apk_(apk), options_(options), commonFeatureGroup_(util::make_unique()) { +} + bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { // Load the manifest std::unique_ptr doc = apk_->LoadXml("AndroidManifest.xml", diag); -- cgit v1.2.3-59-g8ed1b