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

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 12 11:31:40 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL291796: [clang-tidy] Fix check for trivially copyable types in modernize-pass-by-value (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D28614?vs=84135&id=84152#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28614

Files:
  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


Index: clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
@@ -188,7 +188,8 @@
 
   // 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");
Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h
@@ -1,4 +1,7 @@
 class ThreadId {
+public:
+  ThreadId(const ThreadId &) {}
+  ThreadId(ThreadId &&) {}
 };
 
 struct A {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value.cpp
@@ -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 @@
 // 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 @@
 }
 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 @@
   // CHECK-FIXES: T(array<int, 10> a) : a_(a) {}
   array<int, 10> a_;
 };
+
+struct U {
+  U(const POD &M) : M(M) {}
+  POD M;
+};
Index: 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-macro-header.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-macro-header.cpp
@@ -6,6 +6,8 @@
 #include HEADER
 
 struct A {
+  A(const A &) {}
+  A(A &&) {}
 };
 
 struct B {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp
@@ -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)) {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28614.84152.patch
Type: text/x-patch
Size: 3583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170112/05442894/attachment-0001.bin>


More information about the cfe-commits mailing list