Fixed #6154: Don't suggest to reduce scope if inner scope is a lambda.
This commit is contained in:
parent
0a416910c4
commit
865fc9aa67
|
@ -1457,7 +1457,7 @@ void CheckOther::checkVariableScope()
|
|||
bool reduce = true;
|
||||
bool used = false; // Don't warn about unused variables
|
||||
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "{" && tok->scope() != tok->previous()->scope() && !tok->isExpandedMacro()) {
|
||||
if (tok->str() == "{" && tok->scope() != tok->previous()->scope() && !tok->isExpandedMacro() && tok->scope()->type != Scope::eLambda) {
|
||||
if (used) {
|
||||
bool used2 = false;
|
||||
if (!checkInnerScope(tok, var, used2) || used2) {
|
||||
|
|
|
@ -75,6 +75,7 @@ private:
|
|||
TEST_CASE(varScope20); // Ticket #5103
|
||||
TEST_CASE(varScope21); // Ticket #5382
|
||||
TEST_CASE(varScope22); // Ticket #5684
|
||||
TEST_CASE(varScope23); // Ticket #6154
|
||||
|
||||
TEST_CASE(oldStylePointerCast);
|
||||
TEST_CASE(invalidPointerCast);
|
||||
|
@ -1063,6 +1064,16 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'p' can be reduced.\n", errout.str());
|
||||
}
|
||||
|
||||
void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda
|
||||
varScope("int main() {\n"
|
||||
" size_t myCounter = 0;\n"
|
||||
" Test myTest([&](size_t aX){\n"
|
||||
" std::cout << myCounter += aX << std::endl;\n"
|
||||
" });\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkOldStylePointerCast(const char code[]) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
|
Loading…
Reference in New Issue