diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 485d3ff77..fe51596a0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5178,7 +5178,7 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) unsigned int typelen = 1; //check if variable is declared 'const' or 'static' or both - while (Token::Match(tok2, "const|static")) { + while (Token::Match(tok2, "const|static") || Token::Match(tok2, "%type% const|static")) { if (tok2->str() == "const") isconst = true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8bfa780be..f29978bdc 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -294,6 +294,7 @@ private: TEST_CASE(vardecl17); TEST_CASE(vardecl18); TEST_CASE(vardecl19); + TEST_CASE(vardecl20); // #3700 - register const int H = 0; TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_template_1); @@ -4788,6 +4789,18 @@ private: } } + void vardecl20() { + // #3700 + const char code[] = "void a::b() const\n" + "{\n" + " register const int X = 0;\n" + "}\n"; + ASSERT_EQUALS("void a :: b ( ) const\n" + "{\n" + "const int X = 0 ;\n" + "}", tokenizeAndStringify(code)); + } + void volatile_variables() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n"