[clang-tools-extra] r262470 - [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:01:25 PST 2016
Author: hokein
Date: Wed Mar 2 03:01:25 2016
New Revision: 262470
URL: http://llvm.org/viewvc/llvm-project?rev=262470&view=rev
Log:
[clang-tidy] Make 'modernize-pass-by-value' fix work on header files.
Reviewers: alexfh
Subscribers: jbcoe, cfe-commits
Differential Revision: http://reviews.llvm.org/D17756
Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/
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
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.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=262470&r1=262469&r2=262470&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp Wed Mar 2 03:01:25 2016
@@ -208,11 +208,12 @@ void PassByValueCheck::check(const Match
<< 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
Added: 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=262470&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-pass-by-value/header.h Wed Mar 2 03:01:25 2016
@@ -0,0 +1,7 @@
+class ThreadId {
+};
+
+struct A {
+ A(const ThreadId &tid) : threadid(tid) {}
+ ThreadId threadid;
+};
Added: 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=262470&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-pass-by-value-header.cpp Wed Mar 2 03:01:25 2016
@@ -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)) {}
More information about the cfe-commits
mailing list