From 5cf069b2eac72abb31f7897388b7e97958394e83 Mon Sep 17 00:00:00 2001 From: Felka Chang Date: Wed, 27 Oct 2021 00:06:04 +0800 Subject: [PATCH] Fix bugprone-use-after-move in ResourceParser This patch uses reinitialization to solve clang_tidy bugprone-use-after-move warning in ResourceParser. The local variables `comment` in functions is used to record comments in XML. After calling std::move(comment), to use comment.clear() to reinitialize the value of the variable `comment`. Reference: https://clang.llvm.org/extra/clang-tidy/checks/\ bugprone-use-after-move.html Test: export WITH_TIDY=1 ; \ rm -rf out/soong/.intermediates/frameworks/base/tools/aapt2* \ out/host/linux-x86/bin/aapt* \ out/host/windows-x86/bin/aapt* ;\ make aapt2 Bug: 150953574 Change-Id: I5658eaedf48e46fb5e7f12a510b83f490f9bc94b --- tools/aapt2/ResourceParser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index f49c25483e3b1..792a3066f4f6f 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -460,8 +460,8 @@ bool ResourceParser::ParseResources(xml::XmlPullParser* parser) { ParsedResource parsed_resource; parsed_resource.config = config_; parsed_resource.source = source_.WithLine(parser->line_number()); - // NOLINTNEXTLINE(bugprone-use-after-move) move+reset comment parsed_resource.comment = std::move(comment); + comment.clear(); if (options_.visibility) { parsed_resource.visibility_level = options_.visibility.value(); } @@ -1040,6 +1040,7 @@ bool static ParseGroupImpl(xml::XmlPullParser* parser, ParsedResource* out_resou .source = item_source, .comment = std::move(comment), }); + comment.clear(); // Execute group specific code. func(entry_res, next_id); @@ -1788,8 +1789,8 @@ bool ResourceParser::ParseDeclareStyleable(xml::XmlPullParser* parser, ParsedResource child_resource; child_resource.name = child_ref.name.value(); child_resource.source = item_source; - // NOLINTNEXTLINE(bugprone-use-after-move) move+reset comment child_resource.comment = std::move(comment); + comment.clear(); if (options_.visibility) { child_resource.visibility_level = options_.visibility.value(); }