[PATCH] Fix diag message in clang-tidy misc-uniqueptr-reset-release if right side is rvalue
Alexey Sokolov
sokolov at google.com
Wed Mar 4 17:47:00 PST 2015
Hi alexfh,
http://reviews.llvm.org/D8071
Files:
clang-tidy/misc/UniqueptrResetRelease.cpp
test/clang-tidy/misc-uniqueptr-reset-release.cpp
Index: clang-tidy/misc/UniqueptrResetRelease.cpp
===================================================================
--- clang-tidy/misc/UniqueptrResetRelease.cpp
+++ clang-tidy/misc/UniqueptrResetRelease.cpp
@@ -52,13 +52,18 @@
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);
}
Index: test/clang-tidy/misc-uniqueptr-reset-release.cpp
===================================================================
--- test/clang-tidy/misc-uniqueptr-reset-release.cpp
+++ test/clang-tidy/misc-uniqueptr-reset-release.cpp
@@ -33,7 +33,7 @@
// 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)
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8071.21249.patch
Type: text/x-patch
Size: 1853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150305/e6897b29/attachment.bin>
More information about the cfe-commits
mailing list