Bug 1475882 - Enable clang-tidy's misc-swapped-arguments check. r?andi draft
authorChris Peterson <cpeterson@mozilla.com>
Mon, 09 Jul 2018 00:26:58 -0700
changeset 819049 d46d4695a4795be9d9ac50754bdaa441f0928d62
parent 819048 816f0f6ded5d2651258f6b8dcb77568b91aa7e52
child 819050 13e0217f2937ed697fd467ff206e2ac0270bfbb9
push id116421
push usercpeterson@mozilla.com
push dateTue, 17 Jul 2018 01:36:52 +0000
reviewersandi
bugs1475882
milestone63.0a1
Bug 1475882 - Enable clang-tidy's misc-swapped-arguments check. r?andi This check finds potentially swapped function arguments by looking at implicit conversions. There are currently no misc-swapped-arguments warnings in mozilla-central! https://clang.llvm.org/extra/clang-tidy/checks/bugprone-swapped-arguments.html MozReview-Commit-ID: 6SETUcQhQP
tools/clang-tidy/config.yaml
tools/clang-tidy/test/misc-swapped-arguments.cpp
tools/clang-tidy/test/misc-swapped-arguments.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -57,16 +57,18 @@ clang_checkers:
   - name: misc-string-constructor
     publish: !!bool yes
   - name: misc-string-integer-assignment
     publish: !!bool yes
   - name: misc-suspicious-missing-comma
     publish: !!bool yes
   - name: misc-suspicious-semicolon
     publish: !!bool yes
+  - name: misc-swapped-arguments
+    publish: !!bool yes
   - name: misc-unused-using-decls
     publish: !!bool yes
   - name: modernize-avoid-bind
     publish: !!bool yes
     restricted-platforms:
       - win32
       - win64
   - name: modernize-loop-convert
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-swapped-arguments.cpp
@@ -0,0 +1,26 @@
+// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-swapped-arguments.html
+
+void test_d_i(double d, int i);
+void test_d_i_i(double d, int i, int ii);
+void test_i_d(int i, double d);
+void test_i_i_d(int i, int ii, double d);
+
+void test()
+{
+  double d = 1;
+  int i = 1;
+
+  test_d_i(d, i); // OK
+  test_d_i(i, d); // WARNING
+
+  test_i_d(i, d); // OK
+  test_i_d(d, i); // WARNING
+
+  test_i_i_d(i, i, d); // OK
+  test_i_i_d(i, d, i); // WARNING
+  test_i_i_d(d, i, i); // NO WARNING after second parameter
+
+  test_d_i_i(d, i, i); // OK
+  test_d_i_i(i, d, i); // WARNING
+  test_d_i_i(i, i, d); // NO WARNING after second parameter
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-swapped-arguments.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.\", \"misc-swapped-arguments\"], [\"warning\", \"argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.\", \"misc-swapped-arguments\"], [\"warning\", \"argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.\", \"misc-swapped-arguments\"], [\"warning\", \"argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.\", \"misc-swapped-arguments\"]]"
\ No newline at end of file