[PATCH] D17756: [clang-tidy] Make 'modernize-pass-by-value' fix work on header files.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 2 01:06:18 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL262470: [clang-tidy] Make 'modernize-pass-by-value' fix work on header files. (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D17756?vs=49463&id=49588#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17756

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

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
@@ -208,11 +208,12 @@
        << FixItHint::CreateInsertion(
               Initializer->getLParenLoc().getLocWithOffset(1), "std::move(");
 
-  auto Insertion =
-      Inserter->CreateIncludeInsertion(SM.getMainFileID(), "utility",
-                                       /*IsAngled=*/true);
-  if (Insertion.hasValue())
-    Diag << Insertion.getValue();
+  if (auto IncludeFixit = Inserter->CreateIncludeInsertion(
+          Result.SourceManager->getFileID(Initializer->getSourceLocation()),
+          "utility",
+          /*IsAngled=*/true)) {
+    Diag << *IncludeFixit;
+  }
 }
 
 } // namespace modernize
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
@@ -0,0 +1,8 @@
+// RUN: cp %S/Inputs/modernize-pass-by-value/header.h %T/pass-by-value-header.h
+// RUN: clang-tidy %s -checks='-*,modernize-pass-by-value' -header-filter='.*' -fix -- -std=c++11 -I %T | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error}}:"
+// 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-FIXES: #include <utility>
+// CHECK-FIXES: A(ThreadId tid) : threadid(std::move(tid)) {}
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
@@ -0,0 +1,7 @@
+class ThreadId {
+};
+
+struct A {
+  A(const ThreadId &tid) : threadid(tid) {}
+  ThreadId threadid;
+};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17756.49588.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160302/393f48e1/attachment.bin>


More information about the cfe-commits mailing list