Title: [194451] trunk/Source/WTF
- Revision
- 194451
- Author
- [email protected]
- Date
- 2015-12-30 21:24:12 -0800 (Wed, 30 Dec 2015)
Log Message
Use of WTF::move prevents clang's move diagnostics from warning about several classes of mistakes
https://bugs.webkit.org/show_bug.cgi?id=152601
Reviewed by Brady Eidson.
Clang has recently added warnings to catch certain classes of mistakes with the use of std::move():
-Wpessimizing-move (warns if moving prevents copy elision), -Wredundant-move (warns if a move is redundant),
and -Wself-move (warns if moving to self). Enabling these warnings manually (by renaming WTF::move to std::move)
have caught numerous mistakes in our codebase (see http://trac.webkit.org/changeset/194428).
It would be nice to be able to take advantage of these warnings, but doing so requires that we use std::move,
not WTF::move. But since WTF::move does provide useful checks for which clang does not yet have warnings,
we should write a best-of-both-worlds move function.
This patch adds a function that satisfies clang's criteria for a move function (in namespace std, named "move",
and takes a single argument) but also retains WTF::move's compile-time checks. It also adds a convenience macro
called WTF_MOVE for use by callers.
* wtf/StdLibExtras.h:
(std::move):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (194450 => 194451)
--- trunk/Source/WTF/ChangeLog 2015-12-31 01:37:21 UTC (rev 194450)
+++ trunk/Source/WTF/ChangeLog 2015-12-31 05:24:12 UTC (rev 194451)
@@ -1,3 +1,26 @@
+2015-12-30 Andy Estes <[email protected]>
+
+ Use of WTF::move prevents clang's move diagnostics from warning about several classes of mistakes
+ https://bugs.webkit.org/show_bug.cgi?id=152601
+
+ Reviewed by Brady Eidson.
+
+ Clang has recently added warnings to catch certain classes of mistakes with the use of std::move():
+ -Wpessimizing-move (warns if moving prevents copy elision), -Wredundant-move (warns if a move is redundant),
+ and -Wself-move (warns if moving to self). Enabling these warnings manually (by renaming WTF::move to std::move)
+ have caught numerous mistakes in our codebase (see http://trac.webkit.org/changeset/194428).
+
+ It would be nice to be able to take advantage of these warnings, but doing so requires that we use std::move,
+ not WTF::move. But since WTF::move does provide useful checks for which clang does not yet have warnings,
+ we should write a best-of-both-worlds move function.
+
+ This patch adds a function that satisfies clang's criteria for a move function (in namespace std, named "move",
+ and takes a single argument) but also retains WTF::move's compile-time checks. It also adds a convenience macro
+ called WTF_MOVE for use by callers.
+
+ * wtf/StdLibExtras.h:
+ (std::move):
+
2015-12-25 Andy Estes <[email protected]>
Stop moving local objects in return statements
Modified: trunk/Source/WTF/wtf/StdLibExtras.h (194450 => 194451)
--- trunk/Source/WTF/wtf/StdLibExtras.h 2015-12-31 01:37:21 UTC (rev 194450)
+++ trunk/Source/WTF/wtf/StdLibExtras.h 2015-12-31 05:24:12 UTC (rev 194451)
@@ -111,6 +111,8 @@
namespace WTF {
+enum CheckMoveParameterTag { CheckMoveParameter };
+
// FIXME: Using this function prevents Clang's move diagnostics (-Wpessimizing-move, -Wredundant-move, -Wself-move) from
// finding mistakes, since these diagnostics only evaluate calls to std::move().
template<typename T>
@@ -381,8 +383,22 @@
}
}
#endif
+
+template<WTF::CheckMoveParameterTag, typename T>
+ALWAYS_INLINE CONSTEXPR typename remove_reference<T>::type&& move(T&& value)
+{
+ static_assert(is_lvalue_reference<T>::value, "T is not an lvalue reference; move() is unnecessary.");
+
+ using NonRefQualifiedType = typename remove_reference<T>::type;
+ static_assert(!is_const<NonRefQualifiedType>::value, "T is const qualified.");
+
+ return move(forward<T>(value));
}
+} // namespace std
+
+#define WTF_MOVE(value) std::move<WTF::CheckMoveParameter>(value)
+
using WTF::KB;
using WTF::MB;
using WTF::isCompilationThread;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes