Tokenizer::simplifyStaticConst(): Support "struct" and operator:: (#7403)

This commit is contained in:
PKEuS 2016-05-04 12:33:19 +02:00
parent f23668dfcc
commit b65cacf4b1
4 changed files with 5 additions and 5 deletions

View File

@ -5805,7 +5805,7 @@ void Tokenizer::simplifyStaticConst()
// Look backwards to find the beginning of the declaration // Look backwards to find the beginning of the declaration
Token* leftTok = tok; Token* leftTok = tok;
for (; leftTok; leftTok = leftTok->previous()) { for (; leftTok; leftTok = leftTok->previous()) {
if (!Token::Match(leftTok, "%type%|static|const|extern") || if (!Token::Match(leftTok, "%type%|static|const|extern|struct|::") ||
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) (isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator")))
break; break;
} }

View File

@ -667,7 +667,7 @@ private:
void isVariableDeclarationPointerConst() { void isVariableDeclarationPointerConst() {
reset(); reset();
givenACodeSampleToTokenize var("std::string const* s;"); givenACodeSampleToTokenize var("std::string const* s;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); bool result = si.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
ASSERT_EQUALS(true, result); ASSERT_EQUALS(true, result);
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings.library); Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings.library);
ASSERT(false == v.isArray()); ASSERT(false == v.isArray());

View File

@ -3933,7 +3933,7 @@ private:
" a::b const *p = 0;\n" " a::b const *p = 0;\n"
"}\n"; "}\n";
ASSERT_EQUALS("void f ( ) {\n" ASSERT_EQUALS("void f ( ) {\n"
"a :: b const * p ; p = 0 ;\n" "const a :: b * p ; p = 0 ;\n"
"}" "}"
, tokenizeAndStringify(code1)); , tokenizeAndStringify(code1));
@ -3942,7 +3942,7 @@ private:
" ::a::b const *p = 0;\n" " ::a::b const *p = 0;\n"
"}\n"; "}\n";
ASSERT_EQUALS("void f ( ) {\n" ASSERT_EQUALS("void f ( ) {\n"
":: a :: b const * p ; p = 0 ;\n" "const :: a :: b * p ; p = 0 ;\n"
"}" "}"
, tokenizeAndStringify(code2)); , tokenizeAndStringify(code2));
} }

View File

@ -830,7 +830,7 @@ private:
{ {
const char code[] = "void f(FOO::BAR const);\n"; const char code[] = "void f(FOO::BAR const);\n";
ASSERT_EQUALS("\n\n##file 0\n" ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( FOO :: BAR const ) ;\n", "1: void f ( const FOO :: BAR ) ;\n",
tokenize(code)); tokenize(code));
} }
{ {