Fixed #3700 (false positive: (style) Variable 'H' is not assigned a value)

This commit is contained in:
Daniel Marjamäki 2012-04-09 12:55:26 +02:00
parent 26a9a1b571
commit bbdeebafda
2 changed files with 14 additions and 1 deletions

View File

@ -5178,7 +5178,7 @@ 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")) {
while (Token::Match(tok2, "const|static") || Token::Match(tok2, "%type% const|static")) {
if (tok2->str() == "const")
isconst = true;

View File

@ -294,6 +294,7 @@ private:
TEST_CASE(vardecl17);
TEST_CASE(vardecl18);
TEST_CASE(vardecl19);
TEST_CASE(vardecl20); // #3700 - register const int H = 0;
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_template_1);
@ -4788,6 +4789,18 @@ private:
}
}
void vardecl20() {
// #3700
const char code[] = "void a::b() const\n"
"{\n"
" register const int X = 0;\n"
"}\n";
ASSERT_EQUALS("void a :: b ( ) const\n"
"{\n"
"const int X = 0 ;\n"
"}", tokenizeAndStringify(code));
}
void volatile_variables() {
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"