Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Standalone View
test/clang-tidy/readability-function-size.cpp
// RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}, {key: readability-function-size.ParameterThreshold, value: 5}, {key: readability-function-size.NestingThreshold, value: 2}]}' -- -std=c++11 | // RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}, {key: readability-function-size.ParameterThreshold, value: 5}, {key: readability-function-size.NestingThreshold, value: 2}, {key: readability-function-size.VariableThreshold, value: 1}]}' -- -std=c++11 | ||||
// Bad formatting is intentional, don't run clang-format over the whole file! | // Bad formatting is intentional, don't run clang-format over the whole file! | ||||
void foo1() { | void foo1() { | ||||
} | } | ||||
void foo2() {;} | void foo2() {;} | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo2' exceeds recommended size/complexity thresholds [readability-function-size] | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo2' exceeds recommended size/complexity thresholds [readability-function-size] | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// CHECK-MESSAGES: :[[@LINE-4]]:30: warning: function 'barx' exceeds recommended size/complexity | // CHECK-MESSAGES: :[[@LINE-4]]:30: warning: function 'barx' exceeds recommended size/complexity | ||||
// CHECK-MESSAGES: :[[@LINE-5]]:30: note: 2 statements (threshold 0) | // CHECK-MESSAGES: :[[@LINE-5]]:30: note: 2 statements (threshold 0) | ||||
#define macro() {int x; {int y; {int z;}}} | #define macro() {int x; {int y; {int z;}}} | ||||
void baz0() { // 1 | void baz0() { // 1 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'baz0' exceeds recommended size/complexity | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'baz0' exceeds recommended size/complexity | ||||
// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 27 lines including whitespace and comments (threshold 0) | // CHECK-MESSAGES: :[[@LINE-2]]:6: note: 28 lines including whitespace and comments (threshold 0) | ||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 9 statements (threshold 0) | // CHECK-MESSAGES: :[[@LINE-3]]:6: note: 9 statements (threshold 0) | ||||
int a; | int a; | ||||
{ // 2 | { // 2 | ||||
int b; | int b; | ||||
{ // 3 | { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) | ||||
int c; | int c; | ||||
{ // 4 | { // 4 | ||||
int d; | int d; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
{ // 2 | { // 2 | ||||
int e; | int e; | ||||
} | } | ||||
{ // 2 | { // 2 | ||||
{ // 3 | { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) | ||||
int j; | int j; | ||||
} | } | ||||
} | } | ||||
macro() | macro() | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:3: note: nesting level 3 starts here (threshold 2) | ||||
// CHECK-MESSAGES: :[[@LINE-28]]:25: note: expanded from macro 'macro' | // CHECK-MESSAGES: :[[@LINE-28]]:25: note: expanded from macro 'macro' | ||||
// CHECK-MESSAGES: :[[@LINE-27]]:6: note: 6 variables (threshold 1) | |||||
} | } | ||||
// check that nested if's are not reported. this was broken initially | // check that nested if's are not reported. this was broken initially | ||||
void nesting_if() { // 1 | void nesting_if() { // 1 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'nesting_if' exceeds recommended size/complexity | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'nesting_if' exceeds recommended size/complexity | ||||
// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 22 lines including whitespace and comments (threshold 0) | // CHECK-MESSAGES: :[[@LINE-2]]:6: note: 23 lines including whitespace and comments (threshold 0) | ||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 18 statements (threshold 0) | // CHECK-MESSAGES: :[[@LINE-3]]:6: note: 18 statements (threshold 0) | ||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 6 branches (threshold 0) | // CHECK-MESSAGES: :[[@LINE-4]]:6: note: 6 branches (threshold 0) | ||||
if (true) { // 2 | if (true) { // 2 | ||||
int j; | int j; | ||||
} else if (true) { // 2 | } else if (true) { // 2 | ||||
int j; | int j; | ||||
if (true) { // 3 | if (true) { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2) | ||||
int j; | int j; | ||||
} | } | ||||
} else if (true) { // 2 | } else if (true) { // 2 | ||||
int j; | int j; | ||||
if (true) { // 3 | if (true) { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2) | ||||
int j; | int j; | ||||
} | } | ||||
} else if (true) { // 2 | } else if (true) { // 2 | ||||
int j; | int j; | ||||
} | } | ||||
// CHECK-MESSAGES: :[[@LINE-22]]:6: note: 6 variables (threshold 1) | |||||
JonasToth: Why is this check here and not on line 100 like the other conditions? | |||||
Not Done ReplyInline ActionsIt can not be there, the note: nesting level <> starts here (threshold 2) are outputted before note: <> variables (threshold 1), and filecheck respects the order of // CHECK-MESSAGES: lebedev.ri: It can not be there, the `note: nesting level <> starts here (threshold 2)` are outputted… | |||||
Not Done ReplyInline ActionsI see, no problems then :) JonasToth: I see, no problems then :) | |||||
} | } | ||||
// however this should warn | // however this should warn | ||||
void bad_if_nesting() { // 1 | void bad_if_nesting() { // 1 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_if_nesting' exceeds recommended size/complexity | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_if_nesting' exceeds recommended size/complexity | ||||
// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 22 lines including whitespace and comments (threshold 0) | // CHECK-MESSAGES: :[[@LINE-2]]:6: note: 23 lines including whitespace and comments (threshold 0) | ||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 12 statements (threshold 0) | // CHECK-MESSAGES: :[[@LINE-3]]:6: note: 12 statements (threshold 0) | ||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 4 branches (threshold 0) | // CHECK-MESSAGES: :[[@LINE-4]]:6: note: 4 branches (threshold 0) | ||||
if (true) { // 2 | if (true) { // 2 | ||||
int j; | int j; | ||||
} else { // 2 | } else { // 2 | ||||
if (true) { // 3 | if (true) { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:15: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:15: note: nesting level 3 starts here (threshold 2) | ||||
int j; | int j; | ||||
} else { // 3 | } else { // 3 | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: note: nesting level 3 starts here (threshold 2) | // CHECK-MESSAGES: :[[@LINE-1]]:12: note: nesting level 3 starts here (threshold 2) | ||||
if (true) { // 4 | if (true) { // 4 | ||||
int j; | int j; | ||||
} else { // 4 | } else { // 4 | ||||
if (true) { // 5 | if (true) { // 5 | ||||
int j; | int j; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// CHECK-MESSAGES: :[[@LINE-22]]:6: note: 4 variables (threshold 1) | |||||
Not Done ReplyInline Actionssame here. JonasToth: same here. | |||||
} | } | ||||
void variables_0() { | |||||
int i; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_0' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0) | |||||
void variables_1(int i) { | |||||
Could you please add a test for function having more parameters then allowed variables, but no variables? JonasToth: Could you please add a test for function having more parameters then allowed variables, but no… | |||||
Not Done ReplyInline ActionsIt's already checked in foo7(), but sure. lebedev.ri: It's already checked in `foo7()`, but sure. | |||||
int j; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_1' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0) | |||||
void variables_2(int i, int j) { | |||||
; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_2' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0) | |||||
void variables_3() { | |||||
int i[2]; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_3' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0) | |||||
void variables_4() { | |||||
int i; | |||||
int j; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_4' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 2 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1) | |||||
void variables_5() { | |||||
int i, j; | |||||
This testfile is not C++17 right now, but do you know how structured bindings are handled? Maybe its worth adding another file for C++17 testing it. Could you add a little test for range based for loops? JonasToth: This testfile is not C++17 right now, but do you know how structured bindings are handled? | |||||
Not Done ReplyInline Actions
Nice catch!
Added. I expected them to not work (after a quick look at AST), but apparently they just work.. lebedev.ri: > This testfile is not C++17 right now, but do you know how structured bindings are handled? | |||||
Not Done ReplyInline Actions
Life would be so much easier if this is always the case :D JonasToth: > Added. I expected them to not work (after a quick look at AST), but apparently they just work. | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_5' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 2 variables (threshold 1) | |||||
void variables_6() { | |||||
for (int i;;) | |||||
for (int j;;) | |||||
; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_6' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 5 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 branches (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 variables (threshold 1) | |||||
void variables_7() { | |||||
if (int a = 1) | |||||
if (int b = 2) | |||||
; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_7' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 7 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 branches (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 variables (threshold 1) | |||||
void variables_8() { | |||||
int a[2]; | |||||
for (auto i : a) | |||||
for (auto j : a) | |||||
; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: warning: function 'variables_8' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
I think the current behavior here is correct and the previous behavior was incorrect. However, it brings up an interesting question about what to do here: void f() { struct S { void bar() { int a, b; } }; } Does f() contain zero variables or two? I would contend that it has no variables because S::bar() is a different scope than f(). But I can see a case being made about the complexity of f() being increased by the presence of the local class definition. Perhaps this is a different facet of the test about number of types? aaron.ballman: I think the current behavior here is correct and the previous behavior was incorrect. However… | |||||
As previously briefly discussed in IRC, i strongly believe that the current behavior is correct, and readability-function-size lebedev.ri: As previously briefly discussed in IRC, i **strongly** believe that the current behavior is… | |||||
Do you know of any coding standards related to this check that weigh in on this? What do you think about this: #define SWAP(x, y) ({__typeof__(x) temp = x; x = y; y = x;}) void f() { int a = 10, b = 12; SWAP(a, b); } Does f() have two variables or three? Should presence of the SWAP macro cause this code to be more complex due to having too many variables? aaron.ballman: Do you know of any coding standards related to this check that weigh in on this?
What do you… | |||||
Datapoint: the doc (docs/clang-tidy/checks/readability-function-size.rst) actually already states that macros *are* counted. .. option:: StatementThreshold Flag functions exceeding this number of statements. This may differ significantly from the number of lines for macro-heavy code. The default is `800`. .. option:: NestingThreshold Flag compound statements which create next nesting level after `NestingThreshold`. This may differ significantly from the expected value for macro-heavy code. The default is `-1` (ignore the nesting level). lebedev.ri: Datapoint: the doc (`docs/clang-tidy/checks/readability-function-size.rst`) actually already… | |||||
My concerns relate to what's considered a "variable declared in the body" (per the documentation) in relation to function complexity. To me, if the variable is not accessible lexically within the body of the function, it's not adding to the function's complexity *for local variables*. It may certainly be adding other complexity, of course. I would have a very hard time explaining to a user that variables they cannot see or change (assuming the macro is in a header file out of their control) contribute to their function's complexity. Similarly, I would have difficulty explaining that variables in an locally declared class member function contribute to the number of variables in the outer function body, but the class data members somehow do not. aaron.ballman: My concerns relate to what's considered a "variable declared in the body" (per the… | |||||
Please note that the word complexity is not used in the documentation, only size is. There also is the other side of the coin: #define simple_macro_please_ignore \ the; \ actual; \ content; \ of; \ the; \ foo(); // Very simple function, nothing to see. void foo() { simple_macro_please_ignore(); } #undef simple_macro_please_ignore In other words, if we ignore macros, it would be possible to abuse them to artificially reduce complexity, by hiding it in the macros.
Could you please clarify, at this point, your concerns are only about this new part of the check (variables), or for the entire check? lebedev.ri: > (per the documentation)
Please note that the word `complexity` is not used in the… | |||||
I don't disagree, that's why I'm trying to explore the boundaries. Your example does artificially reduce complexity. My example using swap does not -- it's an idiomatic swap macro where the inner variable declaration adds no complexity to the calling function as it's not exposed to the calling function.
Only the new part of the check involving variables. aaron.ballman: > In other words, if we ignore macros, it would be possible to abuse them to artificially… | |||||
OK. This should be split into two boundaries:
I *think* it may make sense to give the latter a pass, no strong opinion here. Does anyone else has an opinion on how that should be handled? lebedev.ri: > > Could you please clarify, at this point, your concerns are only about this new part of the… | |||||
what is the current behaviour for aarons nested function? I think aaron has a good point with:
But I see no way to distinguish between "good" and "bad" macros, so macro expansions should add to the variable count, even though your swap macro is a valid counter example. JonasToth: what is the current behaviour for aarons nested function?
i checked cppcoreguidelines and hicpp… | |||||
I would constrain it this way: variables declared in local class member function definitions and expression statements within a macro expansion do not contribute to the variable count, all other local variables do. e.g., #define SWAP(x, y) ({__typeof__(x) temp = x; x = y; y = x;}) void two_variables() { int a = 10, b = 12; SWAP(a, b); } void three_variables() { int a = 10, b = 12; ({__typeof__(x) temp = x; x = y; y = x;}) } void one_variable() { int i = 12; class C { void four_variables() { int a, b, c, d; } }; } #define FOO(x) (x + ({int i = 12; i;})) void five_variables() { int a, b, c, d = FOO(100); float f; } aaron.ballman: > But I see no way to distinguish between "good" and "bad" macros, so macro expansions should… | |||||
But we do already count statements, branches and compound statements in all those cases in this check. lebedev.ri: > I would constrain it this way: variables declared in local class member function definitions… | |||||
Why should variables be an exception? Why should variables that are entirely inaccessible to the function count towards the function's variable complexity? Things like macros count towards a function's line count because the macros are expanded into the function. I don't agree with this choice, but I can at least explain it to someone I'm teaching. In the case of variable declarations, I have no justification for those variables adding complexity because they cannot be named within the function even though the macro is expanded in the function. Yet the check doesn't count global variables which do add to function complexity when used within the function. For those design reasons, I'd also be opposed to diagnosing this (assume it requires 2 variables to trigger the diagnostic): void one_variable() { auto lambda = []() { int a = 12, b = 100; return a + b; }; } which is functionally equivalent to: void one_variable() { struct S { int operator()() { int a = 12, b = 100; return a + b; } } lambda; } aaron.ballman: > But we do already count statements, branches and compound statements in all those cases in… | |||||
Ok, done. But this raises another question: #define vardecl(type, name) type name; void variables_15() { // FIXME: surely we should still warn here? vardecl(int, a); vardecl(int, b); } I'm guessing we want to still warn in cases like this? lebedev.ri: Ok, done. But this raises another question:
```
#define vardecl(type, name) type name;
void… | |||||
how would you differentiate? I am against trying to get all macro cases right, either warn for everything in macros or nothing. JonasToth: how would you differentiate? I am against trying to get all macro cases right, either warn for… | |||||
That would be nice, yes. That's why the cut-point I was recommending were situations where the declared variables are not accessible within the function. aaron.ballman: > I'm guessing we want to still warn in cases like this?
That would be nice, yes. That's why… | |||||
Ok. Any hint on how to actually do that? lebedev.ri: Ok. Any hint on how to actually do that?
I guess i could look at `DeclRefExpr`, but that would… | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 5 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 8 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 branches (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 3 variables (threshold 1) | |||||
void variables_9() { | |||||
int a, b; | |||||
struct A { | |||||
A(int c, int d) { | |||||
int e, f; | |||||
} | |||||
}; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: warning: function 'variables_9' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 7 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 3 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-11]]:6: note: 2 variables (threshold 1) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:5: warning: function 'A' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-10]]:5: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-11]]:5: note: 1 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-12]]:5: note: 2 variables (threshold 1) | |||||
void variables_10() { | |||||
int a, b; | |||||
struct A { | |||||
int c; | |||||
int d; | |||||
}; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: warning: function 'variables_10' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 6 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 2 variables (threshold 1) | |||||
void variables_11() { | |||||
struct S { | |||||
void bar() { | |||||
int a, b; | |||||
} | |||||
}; | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: warning: function 'variables_11' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 6 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:10: warning: function 'bar' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:10: note: 2 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:10: note: 2 variables (threshold 1) | |||||
void variables_12() { | |||||
int v; | |||||
auto test = [](int a, int b) -> void {}; | |||||
test({}, {}); | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_12' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 3 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 variables (threshold 1) | |||||
void variables_13() { | |||||
int v; | |||||
auto test = []() -> void { | |||||
int a; | |||||
int b; | |||||
}; | |||||
test(); | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-8]]:6: warning: function 'variables_13' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 7 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 5 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-11]]:6: note: 2 variables (threshold 1) | |||||
#define SWAP(x, y) ({__typeof__(x) temp = x; x = y; y = temp; }) | |||||
void variables_14() { | |||||
int a = 10, b = 12; | |||||
SWAP(a, b); | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_14' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 5 statements (threshold 0) | |||||
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1) | |||||
#define vardecl(type, name) type name; | |||||
void variables_15() { | |||||
// FIXME: surely we should still warn here? | |||||
vardecl(int, a); | |||||
vardecl(int, b); | |||||
} | |||||
// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_15' exceeds recommended size/complexity thresholds [readability-function-size] | |||||
// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0) |
Why is this check here and not on line 100 like the other conditions?