[clang-tidy] Fix check for trivially copyable types in modernize-pass-by-value

Summary:
rL270567 excluded trivially copyable types from being moved by
modernize-pass-by-value, but it didn't exclude references to them.
Change types used in the tests to not be trivially copyable.

Reviewers: madsravn, aaron.ballman, alexfh

Subscribers: JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D28614

llvm-svn: 291796
This commit is contained in:
Malcolm Parsons 2017-01-12 19:20:35 +00:00
parent bec58f9034
commit 6b3e27219e
5 changed files with 24 additions and 4 deletions

View File

@ -188,7 +188,8 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
// If the parameter is trivial to copy, don't move it. Moving a trivivally
// copyable type will cause a problem with misc-move-const-arg
if (ParamDecl->getType().isTriviallyCopyableType(*Result.Context))
if (ParamDecl->getType().getNonReferenceType().isTriviallyCopyableType(
*Result.Context))
return;
auto Diag = diag(ParamDecl->getLocStart(), "pass by value and use std::move");

View File

@ -1,4 +1,7 @@
class ThreadId {
public:
ThreadId(const ThreadId &) {}
ThreadId(ThreadId &&) {}
};
struct A {

View File

@ -3,6 +3,6 @@
// RUN: FileCheck -input-file=%T/pass-by-value-header.h %s -check-prefix=CHECK-FIXES
#include "pass-by-value-header.h"
// CHECK-MESSAGES: :5:5: warning: pass by value and use std::move [modernize-pass-by-value]
// CHECK-MESSAGES: :8:5: warning: pass by value and use std::move [modernize-pass-by-value]
// CHECK-FIXES: #include <utility>
// CHECK-FIXES: A(ThreadId tid) : threadid(std::move(tid)) {}

View File

@ -6,6 +6,8 @@
#include HEADER
struct A {
A(const A &) {}
A(A &&) {}
};
struct B {

View File

@ -2,8 +2,15 @@
namespace {
// POD types are trivially move constructible.
struct POD {
int a, b, c;
};
struct Movable {
int a, b, c;
Movable() = default;
Movable(const Movable &) {}
Movable(Movable &&) {}
};
struct NotMovable {
@ -147,7 +154,8 @@ template <typename T> struct N {
// Test with value parameter.
struct O {
O(Movable M) : M(M) {}
// CHECK-FIXES: O(Movable M) : M(M) {}
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass by value and use std::move
// CHECK-FIXES: O(Movable M) : M(std::move(M)) {}
Movable M;
};
@ -179,7 +187,8 @@ typedef ::Movable RMovable;
}
struct R {
R(ns_R::RMovable M) : M(M) {}
// CHECK-FIXES: R(ns_R::RMovable M) : M(M) {}
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass by value and use std::move
// CHECK-FIXES: R(ns_R::RMovable M) : M(std::move(M)) {}
ns_R::RMovable M;
};
@ -199,3 +208,8 @@ struct T {
// CHECK-FIXES: T(array<int, 10> a) : a_(a) {}
array<int, 10> a_;
};
struct U {
U(const POD &M) : M(M) {}
POD M;
};