Skip to content

Commit a6391ae

Browse files
committedMar 6, 2017
[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. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30569 llvm-svn: 297004
1 parent 0243eac commit a6391ae

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎clang-tools-extra/clang-tidy/misc/UseAfterMoveCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) {
398398
const auto *MovingCall = Result.Nodes.getNodeAs<Expr>("moving-call");
399399
const auto *Arg = Result.Nodes.getNodeAs<DeclRefExpr>("arg");
400400

401-
if (!MovingCall)
401+
if (!MovingCall || !MovingCall->getExprLoc().isValid())
402402
MovingCall = CallMove;
403403

404404
Stmt *FunctionBody = nullptr;

‎clang-tools-extra/test/clang-tidy/misc-use-after-move.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void moveInInitList() {
282282
S s{std::move(a)};
283283
a.foo();
284284
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
285-
// CHECK-MESSAGES: [[@LINE-3]]:6: note: move occurred here
285+
// CHECK-MESSAGES: [[@LINE-3]]:7: note: move occurred here
286286
}
287287

288288
void lambdas() {
@@ -397,6 +397,21 @@ void movedTypeIsDependentType() {
397397
}
398398
template void movedTypeIsDependentType<A>();
399399

400+
// We handle the case correctly where the move consists of an implicit call
401+
// to a conversion operator.
402+
void implicitConversionOperator() {
403+
struct Convertible {
404+
operator A() && { return A(); }
405+
};
406+
void takeA(A a);
407+
408+
Convertible convertible;
409+
takeA(std::move(convertible));
410+
convertible;
411+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'convertible' used after it was moved
412+
// CHECK-MESSAGES: [[@LINE-3]]:9: note: move occurred here
413+
}
414+
400415
// Using decltype on an expression is not a use.
401416
void decltypeIsNotUse() {
402417
A a;

0 commit comments

Comments
 (0)
Please sign in to comment.