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
--- 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