[clang-tools-extra] r231365 - [clang-tidy] Fix diag message in clang-tidy misc-uniqueptr-reset-release if right side is rvalue
Alexander Kornienko
alexfh at google.com
Thu Mar 5 05:53:22 PST 2015
Author: alexfh
Date: Thu Mar 5 07:53:21 2015
New Revision: 231365
URL: http://llvm.org/viewvc/llvm-project?rev=231365&view=rev
Log:
[clang-tidy] Fix diag message in clang-tidy misc-uniqueptr-reset-release if right side is rvalue
http://reviews.llvm.org/D8071
Patch by Alexey Sokolov!
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UniqueptrResetRelease.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-uniqueptr-reset-release.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/UniqueptrResetRelease.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UniqueptrResetRelease.cpp?rev=231365&r1=231364&r2=231365&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UniqueptrResetRelease.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UniqueptrResetRelease.cpp Thu Mar 5 07:53:21 2015
@@ -52,13 +52,18 @@ void UniqueptrResetRelease::check(const
LeftText = "*" + LeftText;
if (ReleaseMember->isArrow())
RightText = "*" + RightText;
+ std::string DiagText;
// Even if x was rvalue, *x is not rvalue anymore.
- if (!Right->isRValue() || ReleaseMember->isArrow())
+ if (!Right->isRValue() || ReleaseMember->isArrow()) {
RightText = "std::move(" + RightText + ")";
+ DiagText = "prefer ptr1 = std::move(ptr2) over ptr1.reset(ptr2.release())";
+ } else {
+ DiagText =
+ "prefer ptr = ReturnUnique() over ptr.reset(ReturnUnique().release())";
+ }
std::string NewText = LeftText + " = " + RightText;
- diag(ResetMember->getExprLoc(),
- "prefer ptr1 = std::move(ptr2) over ptr1.reset(ptr2.release())")
+ diag(ResetMember->getExprLoc(), DiagText)
<< FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ResetCall->getSourceRange()), NewText);
}
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-uniqueptr-reset-release.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-uniqueptr-reset-release.cpp?rev=231365&r1=231364&r2=231365&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-uniqueptr-reset-release.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-uniqueptr-reset-release.cpp Thu Mar 5 07:53:21 2015
@@ -33,7 +33,7 @@ void f() {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2)
// CHECK-FIXES: a = std::move(c);
a.reset(Create().release());
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr = ReturnUnique() over ptr.reset(ReturnUnique().release()) [misc-uniqueptr-reset-release]
// CHECK-FIXES: a = Create();
x->reset(y->release());
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: prefer ptr1 = std::move(ptr2)
More information about the cfe-commits
mailing list