From 68e19b33ffae9fb11f8c9ff6e947b8d8271ad4f3 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 10 Jul 2012 06:15:11 -0700 Subject: [PATCH] Fixed parsing of C++11 initializatation in initializer list (#3957) --- lib/symboldatabase.cpp | 5 ++++- test/testsymboldatabase.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ce998986c..bcfb96f22 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 329e99282..818ea7d7a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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 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")