parent
5bea50cd36
commit
4bf8718dcb
|
@ -7321,11 +7321,21 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
|||
if (!tok->next()->link())
|
||||
syntaxError(tokBegin);
|
||||
// Check for lambdas before skipping
|
||||
for (Token* tok2 = tok->next(); tok2 != tok->next()->link(); tok2 = tok2->next()) {
|
||||
Token* lambdaEnd = findLambdaEndScope(tok2);
|
||||
if (!lambdaEnd)
|
||||
continue;
|
||||
simplifyVarDecl(lambdaEnd->link()->next(), lambdaEnd, only_k_r_fpar);
|
||||
if (Token::Match(tok->tokAt(-2), ") . %name%")) { // trailing return type
|
||||
// TODO: support lambda without parameter clause?
|
||||
Token* lambdaStart = tok->linkAt(-2)->previous();
|
||||
if (Token::simpleMatch(lambdaStart, "]"))
|
||||
lambdaStart = lambdaStart->link();
|
||||
Token* lambdaEnd = findLambdaEndScope(lambdaStart);
|
||||
if (lambdaEnd)
|
||||
simplifyVarDecl(lambdaEnd->link()->next(), lambdaEnd, only_k_r_fpar);
|
||||
} else {
|
||||
for (Token* tok2 = tok->next(); tok2 != tok->next()->link(); tok2 = tok2->next()) {
|
||||
Token* lambdaEnd = findLambdaEndScope(tok2);
|
||||
if (!lambdaEnd)
|
||||
continue;
|
||||
simplifyVarDecl(lambdaEnd->link()->next(), lambdaEnd, only_k_r_fpar);
|
||||
}
|
||||
}
|
||||
tok = tok->next()->link();
|
||||
}
|
||||
|
|
|
@ -7888,7 +7888,7 @@ static void valueFlowDynamicBufferSize(TokenList* tokenlist, SymbolDatabase* sym
|
|||
}
|
||||
else {
|
||||
typeTok = newTok->astOperand1();
|
||||
if (typeTok && typeTok->str() == "{")
|
||||
if (typeTok->str() == "{")
|
||||
typeTok = typeTok->astOperand1();
|
||||
}
|
||||
if (bracTok && bracTok->astOperand2() && bracTok->astOperand2()->hasKnownIntValue())
|
||||
|
|
|
@ -620,6 +620,15 @@ private:
|
|||
" for (int i = 0; ;) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class T {};\n" // #10849
|
||||
"void f() {\n"
|
||||
" auto g = [](const T* t) -> int {\n"
|
||||
" const T* u{}, * v{};\n"
|
||||
" return 0;\n"
|
||||
" };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void vardecl() {
|
||||
|
|
|
@ -2687,6 +2687,20 @@ private:
|
|||
const char exp[] = "1: auto g@1 ; g@1 = [ ] ( std :: function < void ( ) > p@2 ) { } ;\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
// # 10849
|
||||
{
|
||||
const char code[] = "class T {};\n"
|
||||
"auto g = [](const T* t) -> int {\n"
|
||||
" const T* u{}, *v{};\n"
|
||||
" return 0;\n"
|
||||
"};\n";
|
||||
const char exp[] = "1: class T { } ;\n"
|
||||
"2: auto g@1 ; g@1 = [ ] ( const T * t@2 ) . int {\n"
|
||||
"3: const T * u@3 { } ; const T * v@4 { } ;\n"
|
||||
"4: return 0 ;\n"
|
||||
"5: } ;\n";
|
||||
ASSERT_EQUALS(exp, tokenize(code));
|
||||
}
|
||||
}
|
||||
|
||||
void varid_lambda_mutable() {
|
||||
|
|
Loading…
Reference in New Issue