Skip to content

Commit baf266d

Browse files
committed
add traverse of ctor-initializers as statements
1 parent bb21a68 commit baf266d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
108108
return true;
109109
}
110110

111+
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
112+
++Info.Statements;
113+
Base::TraverseConstructorInitializer(Init);
114+
return true;
115+
}
116+
111117
struct FunctionInfo {
112118
unsigned Lines = 0;
113119
unsigned Statements = 0;

clang-tools-extra/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ Changes in existing checks
204204
tolerating fix-it breaking compilation when functions is used as pointers
205205
to avoid matching usage of functions within the current compilation unit.
206206

207+
- Improved :doc:`readability-function-size
208+
<clang-tidy/checks/readability/function-size>` check by counting member
209+
initializers in constructors as statements.
210+
207211
Removed checks
208212
^^^^^^^^^^^^^^
209213

clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,23 @@ void variables_16() {
319319
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
320320
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 statements (threshold 0)
321321
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
322+
323+
struct A {
324+
A(int c, int d) : a(0), b(c) {}
325+
int a;
326+
int b;
327+
};
328+
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: function 'A' exceeds recommended size/complexity thresholds [readability-function-size]
329+
// CHECK-MESSAGES: :[[@LINE-5]]:3: note: 2 statements (threshold 0)
330+
331+
struct B {
332+
B(int x, int y, int z) : a(x + y * z), b(), c_a(y, z) {
333+
;
334+
}
335+
int a;
336+
int b;
337+
A c_a;
338+
};
339+
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: function 'B' exceeds recommended size/complexity thresholds [readability-function-size]
340+
// CHECK-MESSAGES: :[[@LINE-8]]:3: note: 2 lines including whitespace and comments (threshold 0)
341+
// CHECK-MESSAGES: :[[@LINE-9]]:3: note: 4 statements (threshold 0)

0 commit comments

Comments
 (0)