[clang-tools-extra] r291796 - [clang-tidy] Fix check for trivially copyable types in modernize-pass-by-value
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 12 11:20:35 PST 2017
Author: malcolm.parsons
Date: Thu Jan 12 13:20:35 2017
New Revision: 291796
URL: http://llvm.org/viewvc/llvm-project?rev=291796&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h
clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp?rev=291796&r1=291795&r2=291796&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp Thu Jan 12 13:20:35 2017
@@ -188,7 +188,8 @@ void PassByValueCheck::check(const Match
// 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");
Modified: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h?rev=291796&r1=291795&r2=291796&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h (original)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h Thu Jan 12 13:20:35 2017
@@ -1,4 +1,7 @@
class ThreadId {
+public:
+ ThreadId(const ThreadId &) {}
+ ThreadId(ThreadId &&) {}
};
struct A {
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp?rev=291796&r1=291795&r2=291796&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp Thu Jan 12 13:20:35 2017
@@ -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)) {}
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp?rev=291796&r1=291795&r2=291796&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp Thu Jan 12 13:20:35 2017
@@ -6,6 +6,8 @@
#include HEADER
struct A {
+ A(const A &) {}
+ A(A &&) {}
};
struct B {
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp?rev=291796&r1=291795&r2=291796&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp Thu Jan 12 13:20:35 2017
@@ -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;
+};
More information about the cfe-commits
mailing list