diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 670c8f8ec..3e223f866 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -1140,12 +1140,13 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList) if (tokenList->back() != par1) addtoken(tokenList, ","); addTypeTokens(tokenList, child->mExtTokens.back()); + const Token *typeEndToken = tokenList->back(); const std::string spelling = child->getSpelling(); Token *vartok = nullptr; if (!spelling.empty()) vartok = child->addtoken(tokenList, spelling); if (!prev) { - function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, i, AccessControl::Argument, nullptr, scope)); + function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, typeEndToken, i, AccessControl::Argument, nullptr, scope)); if (vartok) { const std::string addr = child->mExtTokens[0]; mData->varDecl(addr, vartok, &function->argumentList.back()); @@ -1235,7 +1236,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList) } Token *vartok1 = addtoken(tokenList, name); Scope *scope = const_cast(tokenList->back()->scope()); - scope->varlist.push_back(Variable(vartok1, type, startToken, 0, scope->defaultAccess(), nullptr, scope)); + scope->varlist.push_back(Variable(vartok1, type, startToken, vartok1->previous(), 0, scope->defaultAccess(), nullptr, scope)); mData->varDecl(addr, vartok1, &scope->varlist.back()); if (mExtTokens.back() == "cinit" && !children.empty()) { Token *eq = addtoken(tokenList, "="); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e23794bb1..5f2974022 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1821,12 +1821,12 @@ void SymbolDatabase::clangSetVariables(const std::vector &vari mVariableList = variableList; } -Variable::Variable(const Token *name_, const std::string &clangType, const Token *start, - nonneg int index_, AccessControl access_, const Type *type_, - const Scope *scope_) +Variable::Variable(const Token *name_, const std::string &clangType, const Token *typeStart, + const Token *typeEnd, nonneg int index_, AccessControl access_, + const Type *type_, const Scope *scope_) : mNameToken(name_), - mTypeStartToken(start), - mTypeEndToken(name_ ? name_->previous() : nullptr), + mTypeStartToken(typeStart), + mTypeEndToken(typeEnd), mIndex(index_), mAccess(access_), mFlags(0), diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 18064b735..cc4bf62f4 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -236,9 +236,9 @@ public: evaluate(settings); } - Variable(const Token *name_, const std::string &clangType, const Token *start, - nonneg int index_, AccessControl access_, const Type *type_, - const Scope *scope_); + Variable(const Token *name_, const std::string &clangType, const Token *typeStart, + const Token *typeEnd, nonneg int index_, AccessControl access_, + const Type *type_, const Scope *scope_); ~Variable(); diff --git a/test/cli/test-clang-import.py b/test/cli/test-clang-import.py index 94cd26df3..241719743 100644 --- a/test/cli/test-clang-import.py +++ b/test/cli/test-clang-import.py @@ -94,6 +94,9 @@ def test_symbol_database_3(): def test_symbol_database_4(): check_symbol_database('void f(const int x) {}') +def test_symbol_database_5(): + check_symbol_database('void f(int);') + def test_symbol_database_operator(): check_symbol_database('struct Fred { void operator=(int x); };')