Skip to content

Commit b65cacf

Browse files
committed
Tokenizer::simplifyStaticConst(): Support "struct" and operator:: (cppcheck-opensource#7403)
1 parent f23668d commit b65cacf

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5805,7 +5805,7 @@ void Tokenizer::simplifyStaticConst()
58055805
// Look backwards to find the beginning of the declaration
58065806
Token* leftTok = tok;
58075807
for (; leftTok; leftTok = leftTok->previous()) {
5808-
if (!Token::Match(leftTok, "%type%|static|const|extern") ||
5808+
if (!Token::Match(leftTok, "%type%|static|const|extern|struct|::") ||
58095809
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator")))
58105810
break;
58115811
}

test/testsymboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class TestSymbolDatabase: public TestFixture {
667667
void isVariableDeclarationPointerConst() {
668668
reset();
669669
givenACodeSampleToTokenize var("std::string const* s;");
670-
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
670+
bool result = si.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
671671
ASSERT_EQUALS(true, result);
672672
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings.library);
673673
ASSERT(false == v.isArray());

test/testtokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,7 +3933,7 @@ class TestTokenizer : public TestFixture {
39333933
" a::b const *p = 0;\n"
39343934
"}\n";
39353935
ASSERT_EQUALS("void f ( ) {\n"
3936-
"a :: b const * p ; p = 0 ;\n"
3936+
"const a :: b * p ; p = 0 ;\n"
39373937
"}"
39383938
, tokenizeAndStringify(code1));
39393939

@@ -3942,7 +3942,7 @@ class TestTokenizer : public TestFixture {
39423942
" ::a::b const *p = 0;\n"
39433943
"}\n";
39443944
ASSERT_EQUALS("void f ( ) {\n"
3945-
":: a :: b const * p ; p = 0 ;\n"
3945+
"const :: a :: b * p ; p = 0 ;\n"
39463946
"}"
39473947
, tokenizeAndStringify(code2));
39483948
}

test/testvarid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ class TestVarID : public TestFixture {
830830
{
831831
const char code[] = "void f(FOO::BAR const);\n";
832832
ASSERT_EQUALS("\n\n##file 0\n"
833-
"1: void f ( FOO :: BAR const ) ;\n",
833+
"1: void f ( const FOO :: BAR ) ;\n",
834834
tokenize(code));
835835
}
836836
{

0 commit comments

Comments
 (0)