Bug 1551083 - Enable bugprone-move-forwarding-reference r=andi
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 14 May 2019 07:12:37 +0000
changeset 532563 030c742c25d5e3aab01c2e020345a7cd5506b207
parent 532562 3fae03e3595a90150c92e848ad53bf17f6ed493d
child 532564 5048590d3b69aa6c1d9fd13e388218dc344d214e
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersandi
bugs1551083
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551083 - Enable bugprone-move-forwarding-reference r=andi Differential Revision: https://phabricator.services.mozilla.com/D30816
tools/clang-tidy/config.yaml
tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp
tools/clang-tidy/test/bugprone-move-forwarding-reference.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -35,16 +35,18 @@ clang_checkers:
   - name: bugprone-integer-division
     reliability: high
   - name: bugprone-macro-parentheses
     reliability: medium
   - name: bugprone-macro-repeated-side-effects
     reliability: high
   - name: bugprone-misplaced-widening-cast
     reliability: high
+  - name: bugprone-move-forwarding-reference
+    reliability: high
   - name: bugprone-multiple-statement-macro
     # Incompatible with our code base, see bug 1496379.
     publish: !!bool no
     reliability: high
   - name: bugprone-sizeof-expression
     reliability: high
   - name: bugprone-string-constructor
     reliability: high
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp
@@ -0,0 +1,26 @@
+
+namespace std {
+template <typename> struct remove_reference;
+
+template <typename _Tp> struct remove_reference { typedef _Tp type; };
+
+template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; };
+
+template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template <typename _Tp>
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t);
+
+} // namespace std
+
+// Standard case.
+template <typename T, typename U> void f1(U &&SomeU) {
+  T SomeT(std::move(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+  // CHECK-FIXES: T SomeT(std::forward<U>(SomeU));
+}
+
+void foo() {
+  f1<int, int>(2);
+}
+
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.json
@@ -0,0 +1,1 @@
+[["warning", "forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead", "bugprone-move-forwarding-reference"], {"reliability": "high"}]
\ No newline at end of file