Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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% ,|="
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4142,7 +4142,7 @@ class TestSimplifyTokens : public TestFixture {
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 ) ; "
Expand Down
2 changes: 1 addition & 1 deletion test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ class TestSimplifyTypedef : public TestFixture {
"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));
}

Expand Down
10 changes: 10 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class TestTokenizer : public TestFixture {
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);
Expand Down Expand Up @@ -2075,6 +2076,15 @@ class TestTokenizer : public TestFixture {
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<int> 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;";
Expand Down
2 changes: 1 addition & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ class TestVarID : public TestFixture {

void varid63() {
const char code[] = "void f(boost::optional<int> 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));
}

Expand Down