diff options
author | 2023-05-16 13:54:21 +0000 | |
---|---|---|
committer | 2023-06-07 16:17:22 +0000 | |
commit | 87e94a7bd7cdb2fef51ac94eac70c1f507128f1b (patch) | |
tree | baa7a4557f129b3033ed7bf1098b744be9fefe04 | |
parent | 17a2790f9e1efbcf733af47aa01fd6090bc60c0b (diff) |
Fix "bugprone-use-after-move" clang-tidy issues
Ignore-AOSP-First: changes in libarttools/tools/cmdline_builder_test.cc
are specific to the internal master branch
Bug: 264654008
Test: atest ArtGtestsTargetChroot
Change-Id: I450b73c1faccb5a06f8c99f8d9583ec58b39adba
-rw-r--r-- | build/Android.bp | 1 | ||||
-rw-r--r-- | libartbase/base/bit_vector_test.cc | 1 | ||||
-rw-r--r-- | libartbase/base/scoped_arena_allocator.cc | 2 | ||||
-rw-r--r-- | libartbase/base/unix_file/fd_file_test.cc | 2 | ||||
-rw-r--r-- | libartbase/base/variant_map_test.cc | 2 | ||||
-rw-r--r-- | libarttools/tools/cmdline_builder_test.cc | 1 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 1 |
7 files changed, 9 insertions, 1 deletions
diff --git a/build/Android.bp b/build/Android.bp index 4569b5523f..a8993288d9 100644 --- a/build/Android.bp +++ b/build/Android.bp @@ -36,6 +36,7 @@ art_clang_tidy_errors = [ "bugprone-macro-parentheses", "bugprone-unused-raii", // Protect scoped things like MutexLock. "bugprone-unused-return-value", + "bugprone-use-after-move", "bugprone-virtual-near-miss", "misc-unused-using-decls", "modernize-use-bool-literals", diff --git a/libartbase/base/bit_vector_test.cc b/libartbase/base/bit_vector_test.cc index 5f1b167718..929c3237a0 100644 --- a/libartbase/base/bit_vector_test.cc +++ b/libartbase/base/bit_vector_test.cc @@ -353,6 +353,7 @@ TEST(BitVector, MovementFree) { EXPECT_TRUE(bv.IsBitSet(13)); { BitVector bv2(std::move(bv)); + // NOLINTNEXTLINE - checking underlying storage has been freed ASSERT_TRUE(bv.GetRawStorage() == nullptr); EXPECT_TRUE(bv2.IsBitSet(13)); EXPECT_EQ(alloc.FreeCount(), 0u); diff --git a/libartbase/base/scoped_arena_allocator.cc b/libartbase/base/scoped_arena_allocator.cc index a87064fe40..32de97ad76 100644 --- a/libartbase/base/scoped_arena_allocator.cc +++ b/libartbase/base/scoped_arena_allocator.cc @@ -123,8 +123,10 @@ ScopedArenaAllocator::ScopedArenaAllocator(ScopedArenaAllocator&& other) noexcep mark_arena_(other.mark_arena_), mark_ptr_(other.mark_ptr_), mark_end_(other.mark_end_) { + // NOLINTBEGIN - both ref_count_ and arena_stack_ are still valid after the move other.DebugStackRefCounter::CheckNoRefs(); other.arena_stack_ = nullptr; + // NOLINTEND } ScopedArenaAllocator::ScopedArenaAllocator(ArenaStack* arena_stack) diff --git a/libartbase/base/unix_file/fd_file_test.cc b/libartbase/base/unix_file/fd_file_test.cc index f5933370da..92f8308b8c 100644 --- a/libartbase/base/unix_file/fd_file_test.cc +++ b/libartbase/base/unix_file/fd_file_test.cc @@ -196,7 +196,7 @@ TEST_F(FdFileTest, MoveConstructor) { int old_fd = file.Fd(); FdFile file2(std::move(file)); - EXPECT_FALSE(file.IsOpened()); + EXPECT_FALSE(file.IsOpened()); // NOLINT - checking file is no longer opened after move EXPECT_TRUE(file2.IsOpened()); EXPECT_EQ(old_fd, file2.Fd()); diff --git a/libartbase/base/variant_map_test.cc b/libartbase/base/variant_map_test.cc index f2da3389b1..f7beeceb71 100644 --- a/libartbase/base/variant_map_test.cc +++ b/libartbase/base/variant_map_test.cc @@ -126,6 +126,7 @@ TEST(VariantMaps, RuleOfFive) { // Test move constructor FruitMap fmMoved(std::move(fmFilledCopy)); + // NOLINTNEXTLINE - checking underlying storage has been freed EXPECT_EQ(size_t(0), fmFilledCopy.Size()); EXPECT_EQ(size_t(2), fmMoved.Size()); EXPECT_EQ(*fmFilled.Get(FruitMap::Apple), *fmMoved.Get(FruitMap::Apple)); @@ -136,6 +137,7 @@ TEST(VariantMaps, RuleOfFive) { fmMoved2.Set(FruitMap::Apple, 12345); // This value will be clobbered after the move fmMoved2 = std::move(fmFilledCopy2); + // NOLINTNEXTLINE - checking underlying storage has been freed EXPECT_EQ(size_t(0), fmFilledCopy2.Size()); EXPECT_EQ(size_t(2), fmMoved2.Size()); EXPECT_EQ(*fmFilled.Get(FruitMap::Apple), *fmMoved2.Get(FruitMap::Apple)); diff --git a/libarttools/tools/cmdline_builder_test.cc b/libarttools/tools/cmdline_builder_test.cc index 55518607db..59f41e17ca 100644 --- a/libarttools/tools/cmdline_builder_test.cc +++ b/libarttools/tools/cmdline_builder_test.cc @@ -127,6 +127,7 @@ TEST_F(CmdlineBuilderTest, Concat) { args_.Concat(std::move(other)); EXPECT_THAT(args_.Get(), ElementsAre("--flag1", "--flag2", "--flag3", "--flag4")); + // NOLINTNEXTLINE - checking all args have been moved from other to args_ EXPECT_THAT(other.Get(), IsEmpty()); } diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index fe778e4675..3d7ba535c2 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -810,6 +810,7 @@ class JitCompileTask final : public Task { compilation_kind_(compilation_kind), scoped_compilation_(std::move(sc)) { DCHECK(scoped_compilation_.OwnsCompilation()); + // NOLINTNEXTLINE - OwnsCompilation is still valid after move constructor DCHECK(!sc.OwnsCompilation()); } |