Skip to content

Commit 8f88956

Browse files
committed
Fix weird handling of remark comments
1 parent e4c9d54 commit 8f88956

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

lib/cppcheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger
100100
closePlist();
101101
}
102102

103-
std::vector<RemarkComment>& remarkComments()
103+
void addRemarkComments(std::vector<RemarkComment> remarkComments)
104104
{
105-
return mRemarkComments;
105+
mRemarkComments.insert(mRemarkComments.end(), remarkComments.begin(), remarkComments.end());
106106
}
107107

108108
void setLocationMacros(const Token* startTok, const std::vector<std::string>& files)
@@ -1017,7 +1017,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10171017
}
10181018

10191019
// Parse comments and then remove them
1020-
preprocessor.addRemarkComments(mLogger->remarkComments());
1020+
mLogger->addRemarkComments(preprocessor.getRemarkComments());
10211021
preprocessor.inlineSuppressions(mSuppressions.nomsg);
10221022
preprocessor.removeComments();
10231023

@@ -1062,7 +1062,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10621062

10631063
preprocessor.setLoadCallback([&](simplecpp::FileData &data) {
10641064
// Do preprocessing on included file
1065-
preprocessor.addRemarkComments(data.tokens, mLogger->remarkComments());
1065+
mLogger->addRemarkComments(preprocessor.getRemarkComments(data.tokens));
10661066
preprocessor.inlineSuppressions(data.tokens, mSuppressions.nomsg);
10671067
Preprocessor::removeComments(data.tokens);
10681068
Preprocessor::createDirectives(data.tokens, directives);

lib/preprocessor.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,6 @@ void Preprocessor::inlineSuppressions(const simplecpp::TokenList &tokens, Suppre
352352
}
353353
}
354354

355-
// cppcheck-suppress unusedFunction - only used in tests
356-
std::vector<RemarkComment> Preprocessor::getRemarkComments() const
357-
{
358-
std::vector<RemarkComment> ret;
359-
addRemarkComments(mTokens, ret);
360-
for (const auto &filedata : mFileCache) {
361-
addRemarkComments(filedata->tokens, ret);
362-
}
363-
return ret;
364-
}
365-
366355
void Preprocessor::createDirectives(std::list<Directive> &directives) const
367356
{
368357
createDirectives(mTokens, directives);
@@ -1173,13 +1162,15 @@ void Preprocessor::simplifyPragmaAsm(simplecpp::TokenList &tokenList)
11731162
}
11741163
}
11751164

1176-
void Preprocessor::addRemarkComments(std::vector<RemarkComment>& remarkComments) const
1165+
std::vector<RemarkComment> Preprocessor::getRemarkComments() const
11771166
{
1178-
addRemarkComments(mTokens, remarkComments);
1167+
return getRemarkComments(mTokens);
11791168
}
11801169

1181-
void Preprocessor::addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const
1170+
std::vector<RemarkComment> Preprocessor::getRemarkComments(const simplecpp::TokenList &tokens) const
11821171
{
1172+
std::vector<RemarkComment> remarkComments;
1173+
11831174
for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
11841175
if (!tok->comment)
11851176
continue;
@@ -1226,4 +1217,6 @@ void Preprocessor::addRemarkComments(const simplecpp::TokenList &tokens, std::ve
12261217
// Add the suppressions.
12271218
remarkComments.emplace_back(relativeFilename, remarkedToken->location.line, remarkText);
12281219
}
1220+
1221+
return remarkComments;
12291222
}

lib/preprocessor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
120120

121121
std::vector<RemarkComment> getRemarkComments() const;
122122

123-
void addRemarkComments(std::vector<RemarkComment> &remarkComments) const;
124-
125-
void addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const;
123+
std::vector<RemarkComment> getRemarkComments(const simplecpp::TokenList &tokens) const;
126124

127125
bool loadFiles(std::vector<std::string> &files);
128126

0 commit comments

Comments
 (0)