From 19a05b1f533b7290abae12723c509df9b0708737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 10 Oct 2014 16:46:31 +0200 Subject: [PATCH] Tokenizer::setVarId: don't set varid for 'auto' keyword --- lib/tokenize.cpp | 3 +++ test/testvarid.cpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 098004ec9..0f4745c1a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2601,6 +2601,9 @@ void Tokenizer::setVarId() if (notstart.find(tok2->str()) != notstart.end()) continue; + if (Token::Match(tok2, "const new") && !isC()) + continue; + bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top(), isCPP()); if (decl) { const Token* prev2 = tok2->previous(); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index a5ebf51a7..1c6b9ca09 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -95,6 +95,7 @@ private: TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall4); // ticket #3280 TEST_CASE(varidStl); + TEST_CASE(varid_newauto); // not declaration: new const auto(0); TEST_CASE(varid_delete); TEST_CASE(varid_functions); TEST_CASE(varid_sizeof); @@ -163,7 +164,7 @@ private: Settings settings; settings.standards.c = Standards::C89; - settings.standards.cpp = Standards::CPP03; + settings.standards.cpp = Standards::CPP11; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -1068,7 +1069,7 @@ private: "2: list < int > :: iterator it@2 ;\n" "3: std :: vector < std :: string > dirs@3 ;\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" "7: static std :: vector < CvsProcess * > ex1@7 ;\n" "8: extern std :: vector < CvsProcess * > ex2@8 ;\n" @@ -1078,6 +1079,12 @@ private: 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() { const std::string actual = tokenize( "void f()\n"