Fixed parsing of C++11 initializatation in initializer list (#3957)

This commit is contained in:
PKEuS 2012-07-10 06:15:11 -07:00
parent 37d9d6fd7e
commit 68e19b33ff
2 changed files with 14 additions and 1 deletions

View File

@ -1134,8 +1134,11 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
Scope *new_scope = &scopeList.back();
// skip to start of function
while (tok1 && tok1->str() != "{")
while (tok1 && tok1->str() != "{") {
if (tok1->str() == "(")
tok1 = tok1->link();
tok1 = tok1->next();
}
if (tok1) {
new_scope->classStart = tok1;

View File

@ -103,6 +103,7 @@ private:
TEST_CASE(parseFunctionCorrect);
TEST_CASE(parseFunctionDeclarationCorrect);
TEST_CASE(Cpp11InitInInitList);
TEST_CASE(hasGlobalVariables1);
TEST_CASE(hasGlobalVariables2);
@ -703,6 +704,15 @@ private:
ASSERT_EQUALS(3, db->findScopeByName("func")->classStart->linenr());
}
void Cpp11InitInInitList() {
GET_SYMBOL_DB("class Foo {\n"
" std::vector<std::string> bar;\n"
" Foo() : bar({\"a\", \"b\"})\n"
" {}\n"
"};");
ASSERT_EQUALS(4, db->scopeList.front().nestedList.front()->nestedList.front()->classStart->linenr());
}
void hasGlobalVariables1() {
GET_SYMBOL_DB("int i;\n")