[PATCH] [clang-tidy] Add a checker for long functions.
Alexander Kornienko
alexfh at google.com
Mon Sep 15 05:46:43 PDT 2014
LG.
================
Comment at: clang-tidy/misc/FunctionSize.h:20
@@ +19,3 @@
+class FunctionSizeCheck : public ClangTidyCheck {
+ struct FunctionInfo {
+ FunctionInfo() : Lines(0), Statements(0), Branches(0) {}
----------------
Please move private members to the end for consistency with other ClangTidy classes.
================
Comment at: test/clang-tidy/misc-function-size.cpp:5
@@ +4,3 @@
+// 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:}}'
+
----------------
It seems reasonable to tighten the test a bit by adding the 'note:' prefix to all relevant CHECK lines and to the -implicit-check-not:
-implicit-check-not='{{warning:|error:|note:}}'
...
// CHECK: note: 1 statements (threshold 0)
================
Comment at: test/clang-tidy/misc-function-size.cpp:53
@@ +52,3 @@
+
+void bar2() { class A { void x() {} }; }
+// CHECK: warning: function 'bar2' exceeds recommended size/complexity thresholds
----------------
For the lambda above the check seems to only warn on the function itself, but not on the lambda. I wonder what happens if you add statements inside the x() method. Will the warning only fire for bar2() or for both? I don't know which behavior is better, but it would be good to know what it does currently.
http://reviews.llvm.org/D4986
More information about the cfe-commits
mailing list