parent
fbdfb60809
commit
c9f47dec8b
|
@ -113,7 +113,7 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
|
|||
}
|
||||
if (cpp && tok->str() == ")") {
|
||||
tok = tok->next();
|
||||
while (Token::Match(tok, "const|noexcept|override|final|volatile|&|&& !!(") ||
|
||||
while (Token::Match(tok, "const|noexcept|override|final|volatile|mutable|&|&& !!(") ||
|
||||
(Token::Match(tok, "%name% !!(") && tok->isUpperCaseName()))
|
||||
tok = tok->next();
|
||||
if (tok && tok->str() == ")")
|
||||
|
@ -3552,7 +3552,8 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
|||
}
|
||||
}
|
||||
|
||||
if (cpp && tok3 && Token::simpleMatch(tok3->previous(), "] (") && Token::simpleMatch(tok3->link(), ") {"))
|
||||
if (cpp && tok3 && Token::simpleMatch(tok3->previous(), "] (") &&
|
||||
(Token::simpleMatch(tok3->link(), ") {") || Token::Match(tok3->link(), ") . %name%")))
|
||||
isLambdaArg = true;
|
||||
}
|
||||
|
||||
|
@ -3619,7 +3620,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
|
|||
|
||||
while (Token::Match(tok->next(), ")| . %name% !!(")) {
|
||||
// Don't set varid for trailing return type
|
||||
if (tok->strAt(1) == ")" && tok->linkAt(1)->previous()->isName() &&
|
||||
if (tok->strAt(1) == ")" && (tok->linkAt(1)->previous()->isName() || tok->linkAt(1)->strAt(-1) == "]") &&
|
||||
isFunctionHead(tok->linkAt(1), "{|;")) {
|
||||
tok = tok->tokAt(3);
|
||||
continue;
|
||||
|
@ -5780,7 +5781,7 @@ void Tokenizer::removeMacrosInGlobalScope()
|
|||
if (tok->str() == "(") {
|
||||
tok = tok->link();
|
||||
if (Token::Match(tok, ") %type% {") &&
|
||||
!Token::Match(tok->next(), "const|namespace|class|struct|union|noexcept|override|final|volatile"))
|
||||
!Token::Match(tok->next(), "const|namespace|class|struct|union|noexcept|override|final|volatile|mutable"))
|
||||
tok->deleteNext();
|
||||
}
|
||||
|
||||
|
|
|
@ -2609,34 +2609,56 @@ private:
|
|||
|
||||
void varid_lambda_arg() {
|
||||
// #8664
|
||||
const char code1[] = "static void func(int ec) {\n"
|
||||
" func2([](const std::error_code& ec) { return ec; });\n"
|
||||
"}";
|
||||
const char exp1[] = "1: static void func ( int ec@1 ) {\n"
|
||||
"2: func2 ( [ ] ( const std :: error_code & ec@2 ) { return ec@2 ; } ) ;\n"
|
||||
"3: }\n";
|
||||
ASSERT_EQUALS(exp1, tokenize(code1));
|
||||
|
||||
const char code2[] = "static void func(int ec) {\n"
|
||||
" func2([](int x, const std::error_code& ec) { return x + ec; });\n"
|
||||
"}";
|
||||
const char exp2[] = "1: static void func ( int ec@1 ) {\n"
|
||||
"2: func2 ( [ ] ( int x@2 , const std :: error_code & ec@3 ) { return x@2 + ec@3 ; } ) ;\n"
|
||||
"3: }\n";
|
||||
ASSERT_EQUALS(exp2, tokenize(code2));
|
||||
{
|
||||
const char code[] = "static void func(int ec) {\n"
|
||||
" func2([](const std::error_code& ec) { return ec; });\n"
|
||||
"}";
|
||||
const char exp[] = "1: static void func ( int ec@1 ) {\n"
|
||||
"2: func2 ( [ ] ( const std :: error_code & ec@2 ) { return ec@2 ; } ) ;\n"
|
||||
"3: }\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "static void func(int ec) {\n"
|
||||
" func2([](int x, const std::error_code& ec) { return x + ec; });\n"
|
||||
"}";
|
||||
const char exp[] = "1: static void func ( int ec@1 ) {\n"
|
||||
"2: func2 ( [ ] ( int x@2 , const std :: error_code & ec@3 ) { return x@2 + ec@3 ; } ) ;\n"
|
||||
"3: }\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
// #9384
|
||||
{
|
||||
const char code[] = "auto g = [](const std::string& s) -> std::string { return {}; };\n";
|
||||
const char exp[] = "1: auto g@1 ; g@1 = [ ] ( const std :: string & s@2 ) . std :: string { return { } ; } ;\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "auto g = [](std::function<void()> p) {};\n";
|
||||
const char exp[] = "1: auto g@1 ; g@1 = [ ] ( std :: function < void ( ) > p@2 ) { } ;\n";
|
||||
TODO_ASSERT_EQUALS(exp, "1: auto g@1 ; g@1 = [ ] ( std :: function < void ( ) > p ) { } ;\n", tokenize(code));
|
||||
}
|
||||
}
|
||||
|
||||
void varid_lambda_mutable() {
|
||||
// #8957
|
||||
const char code1[] = "static void func() {\n"
|
||||
" auto x = []() mutable {};\n"
|
||||
" dostuff(x);\n"
|
||||
"}";
|
||||
const char exp1[] = "1: static void func ( ) {\n"
|
||||
"2: auto x@1 ; x@1 = [ ] ( ) mutable { } ;\n"
|
||||
"3: dostuff ( x@1 ) ;\n"
|
||||
"4: }\n";
|
||||
ASSERT_EQUALS(exp1, tokenize(code1));
|
||||
{
|
||||
const char code[] = "static void func() {\n"
|
||||
" auto x = []() mutable {};\n"
|
||||
" dostuff(x);\n"
|
||||
"}";
|
||||
const char exp[] = "1: static void func ( ) {\n"
|
||||
"2: auto x@1 ; x@1 = [ ] ( ) mutable { } ;\n"
|
||||
"3: dostuff ( x@1 ) ;\n"
|
||||
"4: }\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
// #9384
|
||||
{
|
||||
const char code[] = "auto g = [](int i) mutable {};\n";
|
||||
const char exp[] = "1: auto g@1 ; g@1 = [ ] ( int i@2 ) mutable { } ;\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
}
|
||||
|
||||
void varid_trailing_return1() { // #8889
|
||||
|
|
Loading…
Reference in New Issue