Skip to content

Commit e053066

Browse files
committed
Clang import: Fixed Variable::mTypeStartToken and Variable::mTypeEndToken for unnamed parameters
1 parent 488813d commit e053066

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

lib/clangimport.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,12 +1140,13 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
11401140
if (tokenList->back() != par1)
11411141
addtoken(tokenList, ",");
11421142
addTypeTokens(tokenList, child->mExtTokens.back());
1143+
const Token *typeEndToken = tokenList->back();
11431144
const std::string spelling = child->getSpelling();
11441145
Token *vartok = nullptr;
11451146
if (!spelling.empty())
11461147
vartok = child->addtoken(tokenList, spelling);
11471148
if (!prev) {
1148-
function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, i, AccessControl::Argument, nullptr, scope));
1149+
function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, typeEndToken, i, AccessControl::Argument, nullptr, scope));
11491150
if (vartok) {
11501151
const std::string addr = child->mExtTokens[0];
11511152
mData->varDecl(addr, vartok, &function->argumentList.back());
@@ -1235,7 +1236,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)
12351236
}
12361237
Token *vartok1 = addtoken(tokenList, name);
12371238
Scope *scope = const_cast<Scope *>(tokenList->back()->scope());
1238-
scope->varlist.push_back(Variable(vartok1, type, startToken, 0, scope->defaultAccess(), nullptr, scope));
1239+
scope->varlist.push_back(Variable(vartok1, type, startToken, vartok1->previous(), 0, scope->defaultAccess(), nullptr, scope));
12391240
mData->varDecl(addr, vartok1, &scope->varlist.back());
12401241
if (mExtTokens.back() == "cinit" && !children.empty()) {
12411242
Token *eq = addtoken(tokenList, "=");

lib/symboldatabase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,12 +1821,12 @@ void SymbolDatabase::clangSetVariables(const std::vector<const Variable *> &vari
18211821
mVariableList = variableList;
18221822
}
18231823

1824-
Variable::Variable(const Token *name_, const std::string &clangType, const Token *start,
1825-
nonneg int index_, AccessControl access_, const Type *type_,
1826-
const Scope *scope_)
1824+
Variable::Variable(const Token *name_, const std::string &clangType, const Token *typeStart,
1825+
const Token *typeEnd, nonneg int index_, AccessControl access_,
1826+
const Type *type_, const Scope *scope_)
18271827
: mNameToken(name_),
1828-
mTypeStartToken(start),
1829-
mTypeEndToken(name_ ? name_->previous() : nullptr),
1828+
mTypeStartToken(typeStart),
1829+
mTypeEndToken(typeEnd),
18301830
mIndex(index_),
18311831
mAccess(access_),
18321832
mFlags(0),

lib/symboldatabase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ class CPPCHECKLIB Variable {
236236
evaluate(settings);
237237
}
238238

239-
Variable(const Token *name_, const std::string &clangType, const Token *start,
240-
nonneg int index_, AccessControl access_, const Type *type_,
241-
const Scope *scope_);
239+
Variable(const Token *name_, const std::string &clangType, const Token *typeStart,
240+
const Token *typeEnd, nonneg int index_, AccessControl access_,
241+
const Type *type_, const Scope *scope_);
242242

243243
~Variable();
244244

test/cli/test-clang-import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def test_symbol_database_3():
9494
def test_symbol_database_4():
9595
check_symbol_database('void f(const int x) {}')
9696

97+
def test_symbol_database_5():
98+
check_symbol_database('void f(int);')
99+
97100
def test_symbol_database_operator():
98101
check_symbol_database('struct Fred { void operator=(int x); };')
99102

0 commit comments

Comments
 (0)