diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d3ae860ea..08ba5166b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7494,6 +7494,10 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co ++typelen; tok2 = tok2->next(); } + + // east const + if (Token::simpleMatch(tok2, "const")) + isconst = true; } //pattern: "%type% *| ... *| const| %name% ,|=" @@ -7672,6 +7676,13 @@ void Tokenizer::simplifyStaticConst() } if (behindOther) break; + if (isCPP() && Token::simpleMatch(leftTok, ">")) { + Token* opening = leftTok->findOpeningBracket(); + if (opening) { + leftTok = opening; + continue; + } + } if (!Token::Match(leftTok, "%type%|struct|::") || (isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator|template"))) { break; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 374a3f214..e0e553df8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4142,7 +4142,7 @@ private: void simplifyOperator2() { // #6576 ASSERT_EQUALS("template < class T > class SharedPtr { " - "SharedPtr & operator= ( SharedPtr < Y > const & r ) ; " + "SharedPtr & operator= ( const SharedPtr < Y > & r ) ; " "} ; " "class TClass { " "public: TClass & operator= ( const TClass & rhs ) ; " diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index b5941bdb3..a4d478f64 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -1391,7 +1391,7 @@ private: "I i;"; // The expected result.. - const char expected[] = "std :: pair < int , int > const i ;"; + const char expected[] = "const std :: pair < int , int > i ;"; ASSERT_EQUALS(expected, tok(code)); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index bc68b3205..5d87f6765 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -222,6 +222,7 @@ private: TEST_CASE(vardecl28); TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); + TEST_CASE(vardecl_stl_3); TEST_CASE(vardecl_template_1); TEST_CASE(vardecl_template_2); TEST_CASE(vardecl_union); @@ -2075,6 +2076,15 @@ private: ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }", tokenizeAndStringify(code2)); } + void vardecl_stl_3() + { + const char code1[] = "{ std::string const x = \"abc\"; }"; + ASSERT_EQUALS("{ const std :: string x = \"abc\" ; }", tokenizeAndStringify(code1)); + + const char code2[] = "{ std::vector const x = y; }"; + ASSERT_EQUALS("{ const std :: vector < int > x = y ; }", tokenizeAndStringify(code2)); + } + void vardecl_template_1() { // ticket #1046 const char code1[] = "b<(1<<24),10,24> u, v;"; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 37f8b8963..4ae645092 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -1165,7 +1165,7 @@ private: void varid63() { const char code[] = "void f(boost::optional const& x) {}"; - const char expected[] = "1: void f ( boost :: optional < int > const & x@1 ) { }\n"; + const char expected[] = "1: void f ( const boost :: optional < int > & x@1 ) { }\n"; ASSERT_EQUALS(expected, tokenize(code)); }