Fixed #4048 (Tokenizer::simplifyVarDecl: Improve handling of 'a::b const * p = 0;')
This commit is contained in:
parent
929f16d892
commit
9f2e1ab98d
|
@ -4997,13 +4997,29 @@ 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") || Token::Match(tok2, "%type% const|static")) {
|
||||
while (tok2) {
|
||||
if (!Token::Match(tok2, "const|static") && Token::Match(tok2, "%type% const|static")) {
|
||||
tok2 = tok2->next();
|
||||
++typelen;
|
||||
}
|
||||
|
||||
if (tok2->str() == "const")
|
||||
isconst = true;
|
||||
|
||||
else if (tok2->str() == "static")
|
||||
isstatic = true;
|
||||
|
||||
else if (Token::Match(tok2, "%type% :: %type%")) {
|
||||
tok2 = tok2->next();
|
||||
++typelen;
|
||||
}
|
||||
|
||||
else
|
||||
break;
|
||||
|
||||
if (Token::simpleMatch(tok2->next(), "*"))
|
||||
break;
|
||||
|
||||
tok2 = tok2->next();
|
||||
++typelen;
|
||||
}
|
||||
|
|
|
@ -324,6 +324,7 @@ private:
|
|||
TEST_CASE(vardecl18);
|
||||
TEST_CASE(vardecl19);
|
||||
TEST_CASE(vardecl20); // #3700 - register const int H = 0;
|
||||
TEST_CASE(vardecl21); // #4042 - a::b const *p = 0;
|
||||
TEST_CASE(vardecl_stl_1);
|
||||
TEST_CASE(vardecl_stl_2);
|
||||
TEST_CASE(vardecl_template_1);
|
||||
|
@ -5096,6 +5097,16 @@ private:
|
|||
"}", tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void vardecl21() { // #4042
|
||||
const char code[] = "void f() {\n"
|
||||
" a::b const *p = 0;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("void f ( ) {\n"
|
||||
"a :: b const * p ; p = 0 ;\n"
|
||||
"}"
|
||||
, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void volatile_variables() {
|
||||
const char code[] = "volatile int a=0;\n"
|
||||
"volatile int b=0;\n"
|
||||
|
|
Loading…
Reference in New Issue