summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-function-size.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-09-15 12:48:25 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-09-15 12:48:25 +0000
commit6e195426e72282a63f19d0fc448fb1d6730ccd07 (patch)
tree677d16bd904feed3b2a00330397b88690f50ff81 /clang-tools-extra/test/clang-tidy/misc-function-size.cpp
parent707a2e098dd6b30ebf7d6246360c794296eb0ad9 (diff)
downloadbcm5719-llvm-6e195426e72282a63f19d0fc448fb1d6730ccd07.tar.gz
bcm5719-llvm-6e195426e72282a63f19d0fc448fb1d6730ccd07.zip
[clang-tidy] Add a checker for long functions.
As this is very dependent on the code base it has some ways of configuration. It's possible to pick between 3 modes of operation: - Line counting: number of lines including whitespace and comments - Statement counting: number of statements within compoundStmts. - Branch counter In addition a threshold can be picked, warnings are only emitted when it is met. The thresholds can be configured via a .clang-tidy file. Differential Revision: http://reviews.llvm.org/D4986 llvm-svn: 217768
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-function-size.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-function-size.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-function-size.cpp b/clang-tools-extra/test/clang-tidy/misc-function-size.cpp
new file mode 100644
index 00000000000..e0b24215723
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-function-size.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: sed 's#// *[A-Z-][A-Z-]*:.*#//#' %s > %t/t.cpp
+// RUN: echo '{ Checks: "-*,misc-function-size", CheckOptions: [{key: misc-function-size.LineThreshold, value: 0}, {key: misc-function-size.StatementThreshold, value: 0}, {key: misc-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy
+// RUN: clang-tidy %t/t.cpp -- -std=c++11 2>&1 | FileCheck %s -implicit-check-not='{{warning:|error:|note:}}'
+
+void foo1() {
+}
+
+void foo2() {;}
+// CHECK: warning: function 'foo2' exceeds recommended size/complexity thresholds
+// CHECK: note: 1 statements (threshold 0)
+
+void foo3() {
+;
+
+}
+// CHECK: warning: function 'foo3' exceeds recommended size/complexity thresholds
+// CHECK: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK: note: 1 statements (threshold 0)
+
+void foo4(int i) { if (i) {} else; {}
+}
+// CHECK: warning: function 'foo4' exceeds recommended size/complexity thresholds
+// CHECK: note: 1 lines including whitespace and comments (threshold 0)
+// CHECK: note: 3 statements (threshold 0)
+// CHECK: note: 1 branches (threshold 0)
+
+void foo5(int i) {for(;i;)while(i)
+do;while(i);
+}
+// CHECK: warning: function 'foo5' exceeds recommended size/complexity thresholds
+// CHECK: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK: note: 7 statements (threshold 0)
+// CHECK: note: 3 branches (threshold 0)
+
+template <typename T> T foo6(T i) {return i;
+}
+int x = foo6(0);
+// CHECK: warning: function 'foo6' exceeds recommended size/complexity thresholds
+// CHECK: note: 1 lines including whitespace and comments (threshold 0)
+// CHECK: note: 1 statements (threshold 0)
+
+void bar1() { [](){;;;;;;;;;;;if(1){}}();
+
+
+}
+// CHECK: warning: function 'bar1' exceeds recommended size/complexity thresholds
+// CHECK: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK: note: 14 statements (threshold 0)
+// CHECK: note: 1 branches (threshold 0)
+
+void bar2() { class A { void barx() {;;} }; }
+// CHECK: warning: function 'bar2' exceeds recommended size/complexity thresholds
+// CHECK: note: 3 statements (threshold 0)
+//
+// CHECK: warning: function 'barx' exceeds recommended size/complexity thresholds
+// CHECK: note: 2 statements (threshold 0)
OpenPOWER on IntegriCloud