Skip to content

Commit 26788f4

Browse files
authored
fixed #13667 - report functionConst/functionStatic on function implementation (#7383)
1 parent 77b76aa commit 26788f4

File tree

8 files changed

+63
-62
lines changed

8 files changed

+63
-62
lines changed

.selfcheck_suppressions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ noExplicitConstructor:externals/tinyxml2/tinyxml2.h
3030
missingOverride:externals/tinyxml2/tinyxml2.h
3131
invalidPrintfArgType_sint:externals/tinyxml2/tinyxml2.h
3232
naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h
33-
functionStatic:externals/tinyxml2/tinyxml2.h
33+
functionStatic:externals/tinyxml2/tinyxml2.cpp
3434
invalidPrintfArgType_uint:externals/tinyxml2/tinyxml2.cpp
3535
funcArgNamesDifferent:externals/tinyxml2/tinyxml2.cpp
3636
nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
26422642
{
26432643
std::list<const Token *> toks{ tok1 };
26442644
if (tok2)
2645-
toks.push_back(tok2);
2645+
toks.push_front(tok2);
26462646
if (!suggestStatic) {
26472647
const std::string msg = foundAllBaseClasses ?
26482648
"Technically the member function '$symbol' can be const.\nThe member function '$symbol' can be made a const " :

lib/symboldatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
17861786
}
17871787
}
17881788

1789+
// cppcheck-suppress functionConst - has side effects
17891790
void SymbolDatabase::setArrayDimensionsUsingValueFlow()
17901791
{
17911792
// set all unknown array dimensions

lib/symboldatabase.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ class CPPCHECKLIB SymbolDatabase {
14121412
nonneg int sizeOfType(const Token *type) const;
14131413

14141414
/** Set array dimensions when valueflow analysis is completed */
1415-
void setArrayDimensionsUsingValueFlow(); // cppcheck-suppress functionConst // has side effects
1415+
void setArrayDimensionsUsingValueFlow();
14161416

14171417
void clangSetVariables(const std::vector<const Variable *> &variableList);
14181418
void createSymbolDatabaseExprIds();
@@ -1435,14 +1435,12 @@ class CPPCHECKLIB SymbolDatabase {
14351435
void createSymbolDatabaseNeedInitialization();
14361436
void createSymbolDatabaseVariableSymbolTable();
14371437
void createSymbolDatabaseSetScopePointers();
1438-
void createSymbolDatabaseSetFunctionPointers(bool firstPass); // cppcheck-suppress functionConst // has side effects
1438+
void createSymbolDatabaseSetFunctionPointers(bool firstPass);
14391439
void createSymbolDatabaseSetVariablePointers();
1440-
// cppcheck-suppress functionConst
14411440
void createSymbolDatabaseSetTypePointers();
14421441
void createSymbolDatabaseSetSmartPointerType();
1443-
void createSymbolDatabaseEnums(); // cppcheck-suppress functionConst // has side effects
1444-
void createSymbolDatabaseEscapeFunctions(); // cppcheck-suppress functionConst // has side effects
1445-
// cppcheck-suppress functionConst
1442+
void createSymbolDatabaseEnums();
1443+
void createSymbolDatabaseEscapeFunctions();
14461444
void createSymbolDatabaseIncompleteVars();
14471445

14481446
void debugSymbolDatabase() const;

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,7 @@ void Tokenizer::arraySize()
38403840
}
38413841
}
38423842

3843+
// cppcheck-suppress functionConst
38433844
void Tokenizer::arraySizeAfterValueFlow()
38443845
{
38453846
// After ValueFlow, adjust array sizes.
@@ -7092,6 +7093,7 @@ void Tokenizer::simplifyVarDecl(const bool only_k_r_fpar)
70927093
simplifyVarDecl(list.front(), nullptr, only_k_r_fpar);
70937094
}
70947095

7096+
// cppcheck-suppress functionConst - has side effects
70957097
void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, const bool only_k_r_fpar)
70967098
{
70977099
const bool cpp = isCPP();

lib/tokenize.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CPPCHECKLIB Tokenizer {
133133

134134
/** Insert array size where it isn't given */
135135
void arraySize();
136-
void arraySizeAfterValueFlow(); // cppcheck-suppress functionConst
136+
void arraySizeAfterValueFlow();
137137

138138
/** Simplify labels and 'case|default' syntaxes.
139139
*/
@@ -165,7 +165,7 @@ class CPPCHECKLIB Tokenizer {
165165
* \param only_k_r_fpar Only simplify K&R function parameters
166166
*/
167167
void simplifyVarDecl( bool only_k_r_fpar);
168-
void simplifyVarDecl(Token * tokBegin, const Token * tokEnd, bool only_k_r_fpar); // cppcheck-suppress functionConst // has side effects
168+
void simplifyVarDecl(Token * tokBegin, const Token * tokEnd, bool only_k_r_fpar);
169169

170170
/**
171171
* Simplify variable initialization

test/cfg/qt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ namespace {
665665
class Fred : public QObject {
666666
Q_OBJECT
667667
private slots:
668-
// cppcheck-suppress functionStatic
669668
void foo();
670669
};
670+
// cppcheck-suppress functionStatic
671671
void Fred::foo() {}
672672

673673
// bitfields14
@@ -816,13 +816,13 @@ struct DQObject_missingOverride : BQObject_missingOverride {
816816
namespace {
817817
class TestUnusedFunction : public QObject { // #13236
818818
TestUnusedFunction();
819-
// cppcheck-suppress functionStatic
820819
void doStuff();
821820
};
822821

823822
TestUnusedFunction::TestUnusedFunction() {
824823
QObject::connect(this, SIGNAL(doStuff()), SLOT(doStuff()));
825824
}
826825

826+
// cppcheck-suppress functionStatic
827827
void TestUnusedFunction::doStuff() {} // Should not warn here with unusedFunction
828828
}

0 commit comments

Comments
 (0)