diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ee4e441e6..a5eb147c6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7438,7 +7438,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co else if (std::strchr(";,", tok2->str()[0])) { // "type var =" => "type var; var =" const Token *varTok = type0->tokAt(typelen); - while (Token::Match(varTok, "*|&|const|volatile")) + while (Token::Match(varTok, "%name%|*|& %name%|*|&")) varTok = varTok->next(); if (!varTok) syntaxError(tok2); // invalid code diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a7adb40a..07c0a5298 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -215,6 +215,7 @@ private: TEST_CASE(vardecl25); // #4799 - segmentation fault TEST_CASE(vardecl26); // #5907 - incorrect handling of extern declarations TEST_CASE(vardecl27); // #7850 - crash on valid C code + TEST_CASE(vardecl28); TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_template_1); @@ -2473,6 +2474,18 @@ private: 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() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n"