Skip to content

Commit 9d746d0

Browse files
Fix #14632 FN funcArgNamesDifferent when argument is unnamed (#8399)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 2d44419 commit 9d746d0

14 files changed

Lines changed: 78 additions & 27 deletions

.selfcheck_suppressions

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,46 @@ missingIncludeSystem
33
checkersReport
44

55
# warnings in Qt generated code we cannot fix
6+
funcArgNamesDifferentUnnamed:*/moc_aboutdialog.cpp
7+
funcArgNamesDifferentUnnamed:*/moc_applicationdialog.cpp
8+
funcArgNamesDifferentUnnamed:*/moc_applicationlist.cpp
69
funcArgNamesDifferent:*/moc_checkthread.cpp
10+
funcArgNamesDifferentUnnamed:*/moc_checkthread.cpp
11+
funcArgNamesDifferentUnnamed:*/moc_codeeditor.cpp
712
funcArgNamesDifferent:*/moc_codeeditstylecontrols.cpp
13+
funcArgNamesDifferentUnnamed:*/moc_codeeditstylecontrols.cpp
14+
funcArgNamesDifferentUnnamed:*/moc_compliancereportdialog.cpp
15+
funcArgNamesDifferentUnnamed:*/moc_codeeditstyledialog.cpp
16+
funcArgNamesDifferentUnnamed:*/moc_fileviewdialog.cpp
17+
funcArgNamesDifferentUnnamed:*/moc_helpdialog.cpp
18+
funcArgNamesDifferentUnnamed:*/moc_libraryaddfunctiondialog.cpp
19+
funcArgNamesDifferentUnnamed:*/moc_librarydialog.cpp
20+
funcArgNamesDifferentUnnamed:*/moc_libraryeditargdialog.cpp
21+
funcArgNamesDifferentUnnamed:*/moc_mainwindow.cpp
22+
funcArgNamesDifferentUnnamed:*/moc_newsuppressiondialog.cpp
23+
funcArgNamesDifferentUnnamed:*/moc_platforms.cpp
24+
funcArgNamesDifferentUnnamed:*/moc_projectfile.cpp
25+
funcArgNamesDifferentUnnamed:*/moc_projectfiledialog.cpp
826
funcArgNamesDifferent:*/moc_resultstree.cpp
27+
funcArgNamesDifferentUnnamed:*/moc_resultstree.cpp
928
funcArgNamesDifferent:*/moc_resultsview.cpp
29+
funcArgNamesDifferentUnnamed:*/moc_resultsview.cpp
30+
funcArgNamesDifferentUnnamed:*/moc_scratchpad.cpp
31+
funcArgNamesDifferentUnnamed:*/moc_settingsdialog.cpp
32+
funcArgNamesDifferentUnnamed:*/moc_statsdialog.cpp
33+
funcArgNamesDifferentUnnamed:*/moc_testcppchecklibrarydata.cpp
34+
funcArgNamesDifferentUnnamed:*/moc_testfilelist.cpp
35+
funcArgNamesDifferentUnnamed:*/moc_testprojectfile.cpp
36+
funcArgNamesDifferentUnnamed:*/moc_testresultstree.cpp
37+
funcArgNamesDifferentUnnamed:*/moc_testtranslationhandler.cpp
38+
funcArgNamesDifferentUnnamed:*/moc_testxmlreportv2.cpp
39+
funcArgNamesDifferentUnnamed:*/moc_threaddetails.cpp
1040
funcArgNamesDifferent:*/moc_threadhandler.cpp
41+
funcArgNamesDifferentUnnamed:*/moc_threadhandler.cpp
1142
funcArgNamesDifferent:*/moc_threadresult.cpp
43+
funcArgNamesDifferentUnnamed:*/moc_threadresult.cpp
44+
funcArgNamesDifferentUnnamed:*/moc_translationhandler.cpp
45+
funcArgNamesDifferentUnnamed:*/moc_txtreport.cpp
1246
naming-varname:*/gui/ui_*.h
1347
functionStatic:*/gui/ui_*.h
1448

@@ -37,7 +71,10 @@ invalidPrintfArgType_sint:externals/tinyxml2/tinyxml2.h
3771
naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h
3872
functionStatic:externals/tinyxml2/tinyxml2.cpp
3973
funcArgNamesDifferent:externals/tinyxml2/tinyxml2.cpp
74+
funcArgNamesDifferentUnnamed:externals/tinyxml2/tinyxml2.cpp
75+
funcArgNamesDifferentUnnamed:externals/tinyxml2/tinyxml2.h
4076
nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp
4177
knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp
4278
useStlAlgorithm:externals/simplecpp/simplecpp.cpp
79+
funcArgNamesDifferentUnnamed:externals/simplecpp/simplecpp.h
4380
missingMemberCopy:externals/simplecpp/simplecpp.h

gui/codeeditor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ class CodeEditor : public QPlainTextEdit {
129129
void resizeEvent(QResizeEvent *event) override;
130130

131131
private slots:
132-
void updateLineNumberAreaWidth(int newBlockCount);
132+
void updateLineNumberAreaWidth(int /*newBlockCount*/);
133133
void highlightErrorLine();
134-
void updateLineNumberArea(const QRect & /*rect*/, int /*dy*/);
134+
void updateLineNumberArea(const QRect& rect, int dy);
135135

136136
private:
137137
QString generateStyleString();

gui/librarydialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ private slots:
4747
void addFunction();
4848
void changeFunction();
4949
void editArg();
50-
void editFunctionName(QListWidgetItem* /*item*/);
51-
void filterFunctions(const QString& /*filter*/);
50+
void editFunctionName(QListWidgetItem* item);
51+
void filterFunctions(const QString& filter);
5252
void selectFunction();
53-
void sortFunctions(bool /*sort*/);
53+
void sortFunctions(bool sort);
5454

5555
private:
5656
Ui::LibraryDialog *mUi;

gui/projectfiledialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private slots:
280280
/**
281281
* @brief Edit suppression (double clicking on suppression)
282282
*/
283-
void editSuppression(const QModelIndex &index);
283+
void editSuppression(const QModelIndex& /*index*/);
284284

285285
/**
286286
* @brief Browse for misra file

gui/threadresult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ThreadResult : public QObject, public ErrorLogger {
7979
/**
8080
* ErrorLogger methods
8181
*/
82-
void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
82+
void reportOut(const std::string &outmsg, Color /*c*/ = Color::Reset) override;
8383
void reportErr(const ErrorMessage &msg) override;
8484
void reportMetric(const std::string &metric) override
8585
{

lib/checkclass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class CPPCHECKLIB CheckClass : public Check {
138138
void checkUnsafeClassRefMember();
139139

140140
/** @brief Parse current TU and extract file info */
141-
Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& currentConfig) const override;
141+
Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings& /*settings*/, const std::string& currentConfig) const override;
142142

143143
Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override;
144144

lib/checkmemoryleak.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class CPPCHECKLIB CheckMemoryLeakStructMember : public Check, private CheckMemor
266266

267267
void checkStructVariable(const Variable* variable) const;
268268

269-
void getErrorMessages(ErrorLogger * errorLogger, const Settings * settings) const override;
269+
void getErrorMessages(ErrorLogger* /*errorLogger*/, const Settings* /*settings*/) const override;
270270

271271
static std::string myName() {
272272
return "Memory leaks (struct members)";

lib/checkother.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4061,7 +4061,9 @@ void CheckOther::checkFuncArgNamesDifferent()
40614061
// check for different argument names
40624062
if (style && inconclusive) {
40634063
for (int j = 0; j < function->argCount(); ++j) {
4064-
if (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str())
4064+
const bool warn = (declarations[j] != nullptr) != (definitions[j] != nullptr) ||
4065+
(declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str());
4066+
if (warn)
40654067
funcArgNamesDifferent(function->name(), j, declarations[j], definitions[j]);
40664068
}
40674069
}
@@ -4072,11 +4074,12 @@ void CheckOther::funcArgNamesDifferent(const std::string & functionName, nonneg
40724074
const Token* declaration, const Token* definition)
40734075
{
40744076
std::list<const Token *> tokens = { declaration,definition };
4075-
reportError(tokens, Severity::style, "funcArgNamesDifferent",
4077+
const std::string id = (declaration != nullptr) == (definition != nullptr) ? "funcArgNamesDifferent" : "funcArgNamesDifferentUnnamed";
4078+
reportError(tokens, Severity::style, id,
40764079
"$symbol:" + functionName + "\n"
40774080
"Function '$symbol' argument " + std::to_string(index + 1) + " names different: declaration '" +
4078-
(declaration ? declaration->str() : std::string("A")) + "' definition '" +
4079-
(definition ? definition->str() : std::string("B")) + "'.", CWE628, Certainty::inconclusive);
4081+
(declaration ? declaration->str() : "<unnamed>") + "' definition '" +
4082+
(definition ? definition->str() : "<unnamed>") + "'.", CWE628, Certainty::inconclusive);
40804083
}
40814084

40824085
void CheckOther::funcArgOrderDifferent(const std::string & functionName,

lib/checkstl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ void CheckStl::invalidContainer()
12271227
errorPath.insert(errorPath.end(), info.errorPath.cbegin(), info.errorPath.cend());
12281228
errorPath.insert(errorPath.end(), r.errorPath.cbegin(), r.errorPath.cend());
12291229
if (v) {
1230-
invalidContainerError(info.tok, r.tok, v, std::move(errorPath));
1230+
invalidContainerError(info.tok, v, std::move(errorPath));
12311231
} else {
12321232
invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath));
12331233
}
@@ -1252,7 +1252,7 @@ void CheckStl::invalidContainerLoopError(const Token* tok, const Token* loopTok,
12521252
reportError(std::move(errorPath), Severity::error, "invalidContainerLoop", msg, CWE664, Certainty::normal);
12531253
}
12541254

1255-
void CheckStl::invalidContainerError(const Token *tok, const Token * /*contTok*/, const ValueFlow::Value *val, ErrorPath errorPath)
1255+
void CheckStl::invalidContainerError(const Token *tok, const ValueFlow::Value *val, ErrorPath errorPath)
12561256
{
12571257
const bool inconclusive = val ? val->isInconclusive() : false;
12581258
if (val)
@@ -3504,7 +3504,7 @@ void CheckStl::getErrorMessages(ErrorLogger* errorLogger, const Settings* settin
35043504
c.iteratorsError(nullptr, "container1", "container2");
35053505
c.iteratorsError(nullptr, nullptr, "container");
35063506
c.invalidContainerLoopError(nullptr, nullptr, ErrorPath{});
3507-
c.invalidContainerError(nullptr, nullptr, nullptr, ErrorPath{});
3507+
c.invalidContainerError(nullptr, nullptr, ErrorPath{});
35083508
c.invalidContainerReferenceError(nullptr, nullptr, ErrorPath{});
35093509
c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr);
35103510
c.mismatchingContainersError(nullptr, nullptr);

lib/checkstl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CPPCHECKLIB CheckStl : public Check {
187187
void sizeError(const Token* tok);
188188
void redundantIfRemoveError(const Token* tok);
189189
void invalidContainerLoopError(const Token* tok, const Token* loopTok, ErrorPath errorPath);
190-
void invalidContainerError(const Token *tok, const Token * contTok, const ValueFlow::Value *val, ErrorPath errorPath);
190+
void invalidContainerError(const Token *tok, const ValueFlow::Value *val, ErrorPath errorPath);
191191
void invalidContainerReferenceError(const Token* tok, const Token* contTok, ErrorPath errorPath);
192192

193193
void uselessCallsReturnValueError(const Token* tok, const std::string& varname, const std::string& function);

0 commit comments

Comments
 (0)