From 96d29e5761fa84a253b788cde01a165eb664546f Mon Sep 17 00:00:00 2001 From: Martin Bohme Date: Wed, 8 Mar 2017 12:34:51 +0000 Subject: [clang-tidy] misc-use-after-move: Fix failing assertion Summary: I've added a test case that (without the fix) triggers the assertion, which happens when a move happens in an implicitly called conversion operator. This patch also fixes nondeterministic behavior in the source code location reported for the move when the move is constained in an init list; this was causing buildbot failures in the previous attempt to submit this patch (see D30569 and rL297004). Reviewers: alexfh Reviewed By: alexfh Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30650 llvm-svn: 297272 --- .../test/clang-tidy/misc-use-after-move.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp') diff --git a/clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp b/clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp index 92eb1239496..aac901c7690 100644 --- a/clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp @@ -282,7 +282,7 @@ void moveInInitList() { S s{std::move(a)}; a.foo(); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved - // CHECK-MESSAGES: [[@LINE-3]]:6: note: move occurred here + // CHECK-MESSAGES: [[@LINE-3]]:7: note: move occurred here } void lambdas() { @@ -397,6 +397,21 @@ void movedTypeIsDependentType() { } template void movedTypeIsDependentType(); +// We handle the case correctly where the move consists of an implicit call +// to a conversion operator. +void implicitConversionOperator() { + struct Convertible { + operator A() && { return A(); } + }; + void takeA(A a); + + Convertible convertible; + takeA(std::move(convertible)); + convertible; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'convertible' used after it was moved + // CHECK-MESSAGES: [[@LINE-3]]:9: note: move occurred here +} + // Using decltype on an expression is not a use. void decltypeIsNotUse() { A a; -- cgit v1.2.3