Skip to content

Commit 08c53a7

Browse files
danmarclaude
andcommitted
Fix cppcheck warnings and update selfcheck suppressions
- make TokenList::readBlockComment const - use the same parameter name in the constFoldUnaryNotPosNeg declaration and definition - rename the expandTrailingCalls callback parameter so it does not shadow gatherCall - use std::find_if in TokenList::fileIndex - selfcheck: suppress missingMemberCopy and constParameterReference, drop the unmatched missingIncludeSystem suppression Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bc27635 commit 08c53a7

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎.github/workflows/cppcheck.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
--inline-suppr \
5050
--check-level=exhaustive \
5151
--error-exitcode=1 \
52-
--suppress=missingIncludeSystem \
5352
--suppress=checkersReport \
53+
--suppress=missingMemberCopy \
54+
--suppress=constParameterReference \
5455
--template='{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]' \
5556
simplecpp.cpp

‎simplecpp.cpp‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ static simplecpp::TokenString readLineComment(simplecpp::TokenList::Stream &stre
855855
return currentToken;
856856
}
857857

858-
simplecpp::TokenString simplecpp::TokenList::readBlockComment(Stream &stream, unsigned int &multiline)
858+
simplecpp::TokenString simplecpp::TokenList::readBlockComment(Stream &stream, unsigned int &multiline) const
859859
{
860860
TokenString currentToken = "/*";
861861
(void)stream.readChar();
@@ -1840,10 +1840,11 @@ const simplecpp::Token* simplecpp::TokenList::isLastLinePreprocessor(int maxsize
18401840

18411841
unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
18421842
{
1843-
for (unsigned int i = 0; i < files.size(); ++i) {
1844-
if (files[i] == filename)
1845-
return i;
1846-
}
1843+
const auto it = std::find_if(files.cbegin(), files.cend(), [&filename](const std::string &f) {
1844+
return f == filename;
1845+
});
1846+
if (it != files.cend())
1847+
return static_cast<unsigned int>(std::distance(files.cbegin(), it));
18471848
files.emplace_back(filename);
18481849
return files.size() - 1U;
18491850
}
@@ -2671,16 +2672,16 @@ namespace simplecpp {
26712672

26722673
/** Expand while the expansion result in @p temp ends with the name of a
26732674
* function-like macro whose arguments are supplied by the tokens after @p tok.
2674-
* Each round consumes that macro call from the token stream. The @p gatherCall
2675+
* Each round consumes that macro call from the token stream. The @p gather
26752676
* callback copies the macro name and its call into its list and returns the
26762677
* last token of the call, or nullptr when no complete call is available (see
26772678
* gatherCall and gatherCallAfter). Returns the first token that was not
26782679
* consumed (tok->next when no call was expanded). */
26792680
template<class GatherCall>
2680-
const Token *expandTrailingCalls(TokenList &output, TokenList &temp, const Location &loc, const Token *tok, const MacroMap &macros, const std::set<TokenString> &expandedmacros, OutputList *outputList, GatherCall gatherCall) const {
2681+
const Token *expandTrailingCalls(TokenList &output, TokenList &temp, const Location &loc, const Token *tok, const MacroMap &macros, const std::set<TokenString> &expandedmacros, OutputList *outputList, GatherCall gather) const {
26812682
while (const Macro * const calledMacro = callableMacro(temp.cback(), macros, expandedmacros)) {
26822683
TokenList call(files);
2683-
const Token * const last = gatherCall(call, temp.cback(), tok);
2684+
const Token * const last = gather(call, temp.cback(), tok);
26842685
if (!last)
26852686
break;
26862687
output.takeTokens(temp);

‎simplecpp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ namespace simplecpp {
413413

414414
void combineOperators();
415415

416-
void constFoldUnaryNotPosNeg(Token *tok);
416+
void constFoldUnaryNotPosNeg(Token *tok1);
417417
/**
418418
* @throws std::overflow_error thrown on overflow or division by zero
419419
*/
@@ -444,7 +444,7 @@ namespace simplecpp {
444444
* @param multiline incremented for each newline that is removed
445445
* @return the comment text
446446
*/
447-
TokenString readBlockComment(Stream &stream, unsigned int &multiline);
447+
TokenString readBlockComment(Stream &stream, unsigned int &multiline) const;
448448
/**
449449
* Read the text of a #error or #warning directive, up to but not
450450
* including the newline, and add it as one token. A backslash-newline

0 commit comments

Comments
 (0)