Fixed #4799 (Segmentation fault in K&R simplification inside lambda expression)

This commit is contained in:
Frank Zingsheim 2013-05-14 20:56:31 +02:00
parent b58e1241dc
commit 0943fecf03
2 changed files with 9 additions and 1 deletions

View File

@ -5005,7 +5005,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
continue;
} else if (tok->str() == "(") {
for (Token * tok2 = tok; tok2 != tok->link(); tok2 = tok2->next()) {
if (isCPP() && Token::Match(tok2, "[(,] [")) {
if (!only_k_r_fpar && isCPP() && Token::Match(tok2, "[(,] [")) {
// lambda function at tok2->next()
// find start of lambda body
Token * lambdaBody = tok2;

View File

@ -361,6 +361,7 @@ private:
TEST_CASE(vardecl22); // #4211 - segmentation fault
TEST_CASE(vardecl23); // #4276 - segmentation fault
TEST_CASE(vardecl24); // #4187 - variable declaration within lambda function
TEST_CASE(vardecl25); // #4799 - segmentation fault
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_template_1);
@ -5757,6 +5758,13 @@ private:
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2));
}
void vardecl25() { // #4799 - segmentation fault
tokenizeAndStringify("void A::func(P g) const {}\n"
"void A::a() {\n"
" b = new d( [this]( const P & p) -> double { return this->func(p);} );\n"
"}");
}
void volatile_variables() {
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"