Fix bug in Tokenizer::simplifyVarDecl
This commit is contained in:
parent
3c458d8b7b
commit
3c3435dd10
|
@ -7438,7 +7438,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
||||||
else if (std::strchr(";,", tok2->str()[0])) {
|
else if (std::strchr(";,", tok2->str()[0])) {
|
||||||
// "type var =" => "type var; var ="
|
// "type var =" => "type var; var ="
|
||||||
const Token *varTok = type0->tokAt(typelen);
|
const Token *varTok = type0->tokAt(typelen);
|
||||||
while (Token::Match(varTok, "*|&|const|volatile"))
|
while (Token::Match(varTok, "%name%|*|& %name%|*|&"))
|
||||||
varTok = varTok->next();
|
varTok = varTok->next();
|
||||||
if (!varTok)
|
if (!varTok)
|
||||||
syntaxError(tok2); // invalid code
|
syntaxError(tok2); // invalid code
|
||||||
|
|
|
@ -215,6 +215,7 @@ private:
|
||||||
TEST_CASE(vardecl25); // #4799 - segmentation fault
|
TEST_CASE(vardecl25); // #4799 - segmentation fault
|
||||||
TEST_CASE(vardecl26); // #5907 - incorrect handling of extern declarations
|
TEST_CASE(vardecl26); // #5907 - incorrect handling of extern declarations
|
||||||
TEST_CASE(vardecl27); // #7850 - crash on valid C code
|
TEST_CASE(vardecl27); // #7850 - crash on valid C code
|
||||||
|
TEST_CASE(vardecl28);
|
||||||
TEST_CASE(vardecl_stl_1);
|
TEST_CASE(vardecl_stl_1);
|
||||||
TEST_CASE(vardecl_stl_2);
|
TEST_CASE(vardecl_stl_2);
|
||||||
TEST_CASE(vardecl_template_1);
|
TEST_CASE(vardecl_template_1);
|
||||||
|
@ -2473,6 +2474,18 @@ private:
|
||||||
tokenizeAndStringify(code, /*expand=*/true, Settings::Native, "test.c");
|
tokenizeAndStringify(code, /*expand=*/true, Settings::Native, "test.c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vardecl28() {
|
||||||
|
const char code[] = "unsigned short f(void) {\n"
|
||||||
|
" unsigned short const int x = 1;\n"
|
||||||
|
" return x;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS("unsigned short f ( void ) {\n"
|
||||||
|
"const unsigned short x ; x = 1 ;\n"
|
||||||
|
"return x ;\n"
|
||||||
|
"}",
|
||||||
|
tokenizeAndStringify(code, /*expand=*/true, Settings::Native, "test.c"));
|
||||||
|
}
|
||||||
|
|
||||||
void volatile_variables() {
|
void volatile_variables() {
|
||||||
const char code[] = "volatile int a=0;\n"
|
const char code[] = "volatile int a=0;\n"
|
||||||
"volatile int b=0;\n"
|
"volatile int b=0;\n"
|
||||||
|
|
Loading…
Reference in New Issue