-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy] Improve readability-function-size
: count class member initializers as statements
#131669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] Improve readability-function-size
: count class member initializers as statements
#131669
Conversation
baf266d
to
8e49dde
Compare
@llvm/pr-subscribers-clang-tools-extra Author: Baranov Victor (vbvictor) ChangesImprove This PR in draft state until #131406 is merged. Full diff: https://github.com/llvm/llvm-project/pull/131669.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 3313bcb39b7f3..a313d65b5d84c 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -108,6 +108,12 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
return true;
}
+ bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ ++Info.Statements;
+ Base::TraverseConstructorInitializer(Init);
+ return true;
+ }
+
struct FunctionInfo {
unsigned Lines = 0;
unsigned Statements = 0;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..c0f150f6dc8b6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`readability-function-size
+ <clang-tidy/checks/readability/function-size>` check by counting member
+ initializers in constructors as statements.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
index 45b2604b43d03..a9557788f1d75 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
@@ -319,3 +319,23 @@ void variables_16() {
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 statements (threshold 0)
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
+
+struct A {
+ A(int c, int d) : a(0), b(c) {}
+ int a;
+ int b;
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: function 'A' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:3: note: 2 statements (threshold 0)
+
+struct B {
+ B(int x, int y, int z) : a(x + y * z), b(), c_a(y, z) {
+ ;
+ }
+ int a;
+ int b;
+ A c_a;
+};
+// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: function 'B' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-8]]:3: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:3: note: 4 statements (threshold 0)
|
@llvm/pr-subscribers-clang-tidy Author: Baranov Victor (vbvictor) ChangesImprove This PR in draft state until #131406 is merged. Full diff: https://github.com/llvm/llvm-project/pull/131669.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 3313bcb39b7f3..a313d65b5d84c 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -108,6 +108,12 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
return true;
}
+ bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ ++Info.Statements;
+ Base::TraverseConstructorInitializer(Init);
+ return true;
+ }
+
struct FunctionInfo {
unsigned Lines = 0;
unsigned Statements = 0;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..c0f150f6dc8b6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`readability-function-size
+ <clang-tidy/checks/readability/function-size>` check by counting member
+ initializers in constructors as statements.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
index 45b2604b43d03..a9557788f1d75 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp
@@ -319,3 +319,23 @@ void variables_16() {
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 statements (threshold 0)
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
+
+struct A {
+ A(int c, int d) : a(0), b(c) {}
+ int a;
+ int b;
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: function 'A' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:3: note: 2 statements (threshold 0)
+
+struct B {
+ B(int x, int y, int z) : a(x + y * z), b(), c_a(y, z) {
+ ;
+ }
+ int a;
+ int b;
+ A c_a;
+};
+// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: function 'B' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-8]]:3: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:3: note: 4 statements (threshold 0)
|
This comment was marked as outdated.
This comment was marked as outdated.
8e49dde
to
a5e8c2f
Compare
a5e8c2f
to
2b4699f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
…ility-function-size' (llvm#131669) Improve `readability-function-size` by counting class member initializers as statements. Relates to llvm#131126
Improve
readability-function-size
by counting class member initializers as statements.Relates to #131126 (comment).