[PATCH] D74463: Add new check avoid-adjacent-unrelated-parameters-of-the-same-type

2020-02-11 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal updated this revision to Diff 244072.
vingeldal added a comment.

Updating D74463 : Add new check 
avoid-adjacent-unrelated-parameters-of-the-same-type

- Changed commit message to start with [clang-tidy]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74463/new/

https://reviews.llvm.org/D74463

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidAdjacentParametersOfTheSameTypeCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidAdjacentParametersOfTheSameTypeCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type %t
+
+void func_no_parameter();
+
+void func_parameter_argument(int arg1);
+
+void func_int_int_array(int arg1, int arg2[]);
+
+void func_int_int_reference(int arg1, int );
+
+void func_int_int_pointer(int arg1, int *arg2);
+
+void func_int_const_int(int arg1, const int arg2);
+
+void func_int_unsigned_int(int arg1, unsigned int arg2);
+
+void func_int_long_int(int arg1, long int arg2);
+
+void func_int_float(int arg1, float arg2);
+
+void func_more_than_two_different(char arg1, int arg2, float arg3);
+
+enum DummyEnum { first,
+ second };
+void func_int_and_enum(int arg1, DummyEnum arg2);
+
+template 
+void func_template(T arg1, int arg2);
+
+template 
+void func_template_adjacent_int(T arg1, int arg2, int arg3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template_adjacent_int' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+template 
+void func_template_adjacent_template_type(T arg1, T arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template_adjacent_template_type' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_two_adjacent_int(int arg1, int arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_two_adjacent_int' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_int_more_than_two(int arg1, int arg2, int int_3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_int_more_than_two' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_int_not_all_same(float arg1, int arg2, int int_3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_int_not_all_same' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_float(float arg1, float arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_float' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+class DummyClass {
+public:
+  void func_member1();
+  void func_member2(int arg1, int arg2, float arg3);
+  static void func_member3(int arg1, int arg2);
+};
+// CHECK-MESSAGES: :[[@LINE-3]]:10: warning: function 'func_member2' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+// CHECK-MESSAGES: :[[@LINE-3]]:17: warning: function 'func_member3' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
\ No newline at end of file
Index: 

[PATCH] D74463: Add new check avoid-adjacent-unrelated-parameters-of-the-same-type

2020-02-11 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal created this revision.
Herald added subscribers: cfe-commits, kbarton, mgorny, nemanjai.
Herald added a project: clang.

This check is part of the C++ Core Guidelines, rule I.24
https://github.com/vingeldal/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-unrelated


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74463

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidAdjacentParametersOfTheSameTypeCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidAdjacentParametersOfTheSameTypeCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type.cpp
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type %t
+
+void func_no_parameter();
+
+void func_parameter_argument(int arg1);
+
+void func_int_int_array(int arg1, int arg2[]);
+
+void func_int_int_reference(int arg1, int );
+
+void func_int_int_pointer(int arg1, int *arg2);
+
+void func_int_const_int(int arg1, const int arg2);
+
+void func_int_unsigned_int(int arg1, unsigned int arg2);
+
+void func_int_long_int(int arg1, long int arg2);
+
+void func_int_float(int arg1, float arg2);
+
+void func_more_than_two_different(char arg1, int arg2, float arg3);
+
+enum DummyEnum { first,
+ second };
+void func_int_and_enum(int arg1, DummyEnum arg2);
+
+template 
+void func_template(T arg1, int arg2);
+
+template 
+void func_template_adjacent_int(T arg1, int arg2, int arg3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template_adjacent_int' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+template 
+void func_template_adjacent_template_type(T arg1, T arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template_adjacent_template_type' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_two_adjacent_int(int arg1, int arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_two_adjacent_int' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_int_more_than_two(int arg1, int arg2, int int_3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_int_more_than_two' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_int_not_all_same(float arg1, int arg2, int int_3);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_int_not_all_same' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+void func_adjacent_float(float arg1, float arg2);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_adjacent_float' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+
+class DummyClass {
+public:
+  void func_member1();
+  void func_member2(int arg1, int arg2, float arg3);
+  static void func_member3(int arg1, int arg2);
+};
+// CHECK-MESSAGES: :[[@LINE-3]]:10: warning: function 'func_member2' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
+// CHECK-MESSAGES: :[[@LINE-3]]:17: warning: function 'func_member3' has adjacent parameters of the same type. If the order of these parameters matter consider rewriting this to avoid a mixup of parameters. [cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type]
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst