Tokenizer::setVarId: don't set varid for 'auto' keyword

This commit is contained in:
Daniel Marjamäki 2014-10-10 16:46:31 +02:00
parent d0d2a0faf8
commit 19a05b1f53
2 changed files with 12 additions and 2 deletions

View File

@ -2601,6 +2601,9 @@ void Tokenizer::setVarId()
if (notstart.find(tok2->str()) != notstart.end()) if (notstart.find(tok2->str()) != notstart.end())
continue; continue;
if (Token::Match(tok2, "const new") && !isC())
continue;
bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top(), isCPP()); bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top(), isCPP());
if (decl) { if (decl) {
const Token* prev2 = tok2->previous(); const Token* prev2 = tok2->previous();

View File

@ -95,6 +95,7 @@ private:
TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall3);
TEST_CASE(varidFunctionCall4); // ticket #3280 TEST_CASE(varidFunctionCall4); // ticket #3280
TEST_CASE(varidStl); TEST_CASE(varidStl);
TEST_CASE(varid_newauto); // not declaration: new const auto(0);
TEST_CASE(varid_delete); TEST_CASE(varid_delete);
TEST_CASE(varid_functions); TEST_CASE(varid_functions);
TEST_CASE(varid_sizeof); TEST_CASE(varid_sizeof);
@ -163,7 +164,7 @@ private:
Settings settings; Settings settings;
settings.standards.c = Standards::C89; settings.standards.c = Standards::C89;
settings.standards.cpp = Standards::CPP03; settings.standards.cpp = Standards::CPP11;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
@ -1068,7 +1069,7 @@ private:
"2: list < int > :: iterator it@2 ;\n" "2: list < int > :: iterator it@2 ;\n"
"3: std :: vector < std :: string > dirs@3 ;\n" "3: std :: vector < std :: string > dirs@3 ;\n"
"4: std :: map < int , int > coords@4 ;\n" "4: std :: map < int , int > coords@4 ;\n"
"5: std :: tr1 :: unordered_map < int , int > xy@5 ;\n" "5: std :: unordered_map < int , int > xy@5 ;\n"
"6: std :: list < boost :: wave :: token_id > tokens@6 ;\n" "6: std :: list < boost :: wave :: token_id > tokens@6 ;\n"
"7: static std :: vector < CvsProcess * > ex1@7 ;\n" "7: static std :: vector < CvsProcess * > ex1@7 ;\n"
"8: extern std :: vector < CvsProcess * > ex2@8 ;\n" "8: extern std :: vector < CvsProcess * > ex2@8 ;\n"
@ -1078,6 +1079,12 @@ private:
ASSERT_EQUALS(expected, actual); ASSERT_EQUALS(expected, actual);
} }
void varid_newauto() {
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( ) { const new auto ( 0 ) ; }\n",
tokenize("void f(){new const auto(0);}"));
}
void varid_delete() { void varid_delete() {
const std::string actual = tokenize( const std::string actual = tokenize(
"void f()\n" "void f()\n"