Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4140,7 +4140,8 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li
return v.nameToken();
}
auto it = std::find_if(scope->functionList.cbegin(), scope->functionList.cend(), [&](const Function& f) {
return f.type == FunctionType::eFunction && f.name() == var.name() && precedes(f.tokenDef, var.nameToken());
return f.type == FunctionType::eFunction && f.name() == var.name()
&& (scope->isClassOrStructOrUnion() || precedes(f.tokenDef, var.nameToken()));
});
if (it != scope->functionList.end())
return it->tokenDef;
Expand Down
8 changes: 4 additions & 4 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class FileWithDetails
throw std::runtime_error("empty path specified");
}

void setPath(std::string path)
void setPath(std::string p)
{
mPath = std::move(path);
mPath = std::move(p);
mPathSimplified = Path::simplifyPath(mPath);
mPathAbsolute.clear();
}
Expand Down Expand Up @@ -76,9 +76,9 @@ class FileWithDetails
return mSize;
}

void setLang(Standards::Language lang)
void setLang(Standards::Language language)
{
mLang = lang;
mLang = language;
}

Standards::Language lang() const
Expand Down
42 changes: 21 additions & 21 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,35 +249,35 @@ class CPPCHECKLIB Token {
* For example index 1 would return next token, and 2
* would return next from that one.
*/
const Token *tokAt(int index) const
const Token *tokAt(int idx) const
{
return tokAtImpl(this, index);
return tokAtImpl(this, idx);
}
Token *tokAt(int index)
Token *tokAt(int idx)
{
return tokAtImpl(this, index);
return tokAtImpl(this, idx);
}

/**
* @return the link to the token in given index, related to this token.
* For example index 1 would return the link to next token.
*/
const Token *linkAt(int index) const
const Token *linkAt(int idx) const
{
return linkAtImpl(this, index);
return linkAtImpl(this, idx);
}
Token *linkAt(int index)
Token *linkAt(int idx)
{
return linkAtImpl(this, index);
return linkAtImpl(this, idx);
}

/**
* @return String of the token in given index, related to this token.
* If that token does not exist, an empty string is being returned.
*/
const std::string &strAt(int index) const
const std::string &strAt(int idx) const
{
const Token *tok = this->tokAt(index);
const Token *tok = this->tokAt(idx);
return tok ? tok->mStr : mEmptyString;
}

Expand Down Expand Up @@ -604,11 +604,11 @@ class CPPCHECKLIB Token {
bool hasAttributeCleanup() const {
return !mImpl->mAttributeCleanup.empty();
}
void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value) {
mImpl->setCppcheckAttribute(type, value);
void setCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint value) {
mImpl->setCppcheckAttribute(attrType, value);
}
bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const {
return mImpl->getCppcheckAttribute(type, value);
bool getCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint &value) const {
return mImpl->getCppcheckAttribute(attrType, value);
}
// cppcheck-suppress unusedFunction
bool hasCppcheckAttributes() const {
Expand Down Expand Up @@ -891,15 +891,15 @@ class CPPCHECKLIB Token {

private:
template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
static T *tokAtImpl(T *tok, int index)
static T *tokAtImpl(T *tok, int idx)
{
while (index > 0 && tok) {
while (idx > 0 && tok) {
tok = tok->next();
--index;
--idx;
}
while (index < 0 && tok) {
while (idx < 0 && tok) {
tok = tok->previous();
++index;
++idx;
}
return tok;
}
Expand All @@ -908,9 +908,9 @@ class CPPCHECKLIB Token {
* @throws InternalError thrown if index is out of range
*/
template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
static T *linkAtImpl(T *thisTok, int index)
static T *linkAtImpl(T *thisTok, int idx)
{
T *tok = thisTok->tokAt(index);
T *tok = thisTok->tokAt(idx);
if (!tok) {
throw InternalError(thisTok, "Internal error. Token::linkAt called with index outside the tokens range.");
}
Expand Down
18 changes: 9 additions & 9 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,23 +568,23 @@ namespace {
const std::pair<Token*, Token*> rangeBefore(start, Token::findsimplematch(start, "{"));

// find typedef name token
Token* nameToken = rangeBefore.second->link()->next();
while (Token::Match(nameToken, "%name%|* %name%|*"))
nameToken = nameToken->next();
const std::pair<Token*, Token*> rangeQualifiers(rangeBefore.second->link()->next(), nameToken);
Token* nameTok = rangeBefore.second->link()->next();
while (Token::Match(nameTok, "%name%|* %name%|*"))
nameTok = nameTok->next();
const std::pair<Token*, Token*> rangeQualifiers(rangeBefore.second->link()->next(), nameTok);

if (Token::Match(nameToken, "%name% ;")) {
if (Token::Match(nameTok, "%name% ;")) {
if (Token::Match(rangeBefore.second->previous(), "enum|struct|union|class {"))
rangeBefore.second->previous()->insertToken(nameToken->str());
rangeBefore.second->previous()->insertToken(nameTok->str());
mRangeType = rangeBefore;
mRangeTypeQualifiers = rangeQualifiers;
Token* typeName = rangeBefore.second->previous();
if (typeName->isKeyword()) {
// TODO typeName->insertToken("T:" + std::to_string(num++));
typeName->insertToken(nameToken->str());
typeName->insertToken(nameTok->str());
}
mNameToken = nameToken;
mEndToken = nameToken->next();
mNameToken = nameTok;
mEndToken = nameTok->next();
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13124,6 +13124,9 @@ class TestOther : public TestFixture {

check("struct S { static int i(); static void f(int i) {} };\n");
ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:46]: (style) Argument 'i' shadows outer function [shadowFunction]\n", errout_str());

check("struct S { void g(float f) {} void f() {} };\n");
ASSERT_EQUALS("[test.cpp:1:36] -> [test.cpp:1:25]: (style) Argument 'f' shadows outer function [shadowFunction]\n", errout_str());
}

void knownArgument() {
Expand Down
4 changes: 2 additions & 2 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class TestPreprocessor : public TestFixture {
cfgs = preprocessor.getConfigs();
for (const std::string & config : cfgs) {
try {
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
cfgcode[config] = preprocessor.getcode(config, files, writeLocations);
const bool writeLocs = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
cfgcode[config] = preprocessor.getcode(config, files, writeLocs);
} catch (const simplecpp::Output &) {
cfgcode[config] = "";
}
Expand Down
Loading