llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)

<details>
<summary>Changes</summary>

Improve `readability-function-size` by counting class member initializers as 
statements.
Relates to 
https://github.com/llvm/llvm-project/issues/131126#issuecomment-2725906714.

This PR in draft state until https://github.com/llvm/llvm-project/pull/131406 
is merged.


---
Full diff: https://github.com/llvm/llvm-project/pull/131669.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp 
(+6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/function-size.cpp (+20) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/131669
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to