Skip to content

Commit 847fbbc

Browse files
committed
checkimpl
1 parent d78fcef commit 847fbbc

2 files changed

Lines changed: 34 additions & 29 deletions

File tree

lib/checkboost.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "checkboost.h"
2020

21+
#include "checkimpl.h"
2122
#include "errortypes.h"
2223
#include "symboldatabase.h"
2324
#include "token.h"
@@ -31,7 +32,20 @@ namespace {
3132

3233
static const CWE CWE664(664);
3334

34-
void CheckBoost::checkBoostForeachModification()
35+
class CheckBoostImpl : public CheckImpl
36+
{
37+
public:
38+
/** This constructor is used when running checks. */
39+
CheckBoostImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
40+
: CheckImpl(tokenizer, settings, errorLogger) {}
41+
42+
/** @brief %Check for container modification while using the BOOST_FOREACH macro */
43+
void checkBoostForeachModification();
44+
45+
void boostForeachError(const Token *tok);
46+
};
47+
48+
void CheckBoostImpl::checkBoostForeachModification()
3549
{
3650
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
3751
for (const Scope * scope : symbolDatabase->functionScopes) {
@@ -57,9 +71,24 @@ void CheckBoost::checkBoostForeachModification()
5771
}
5872
}
5973

60-
void CheckBoost::boostForeachError(const Token *tok)
74+
void CheckBoostImpl::boostForeachError(const Token *tok)
6175
{
6276
reportError(tok, Severity::error, "boostForeachError",
6377
"BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.", CWE664, Certainty::normal
6478
);
6579
}
80+
81+
void CheckBoost::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
82+
{
83+
if (!tokenizer.isCPP())
84+
return;
85+
86+
CheckBoostImpl checkBoost(&tokenizer, tokenizer.getSettings(), errorLogger);
87+
checkBoost.checkBoostForeachModification();
88+
}
89+
90+
void CheckBoost::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
91+
{
92+
CheckBoostImpl c(nullptr, settings, errorLogger);
93+
c.boostForeachError(nullptr);
94+
}

lib/checkboost.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424

2525
#include "check.h"
2626
#include "config.h"
27-
#include "tokenize.h"
2827

2928
#include <string>
3029

3130
class ErrorLogger;
3231
class Settings;
33-
class Token;
3432

3533
/// @addtogroup Checks
3634
/// @{
@@ -40,35 +38,13 @@ class Token;
4038
class CPPCHECKLIB CheckBoost : public Check {
4139
public:
4240
/** This constructor is used when registering the CheckClass */
43-
CheckBoost() : Check(myName()) {}
44-
45-
/** This constructor is used when running checks. */
46-
CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
47-
: Check(myName(), tokenizer, settings, errorLogger) {}
41+
CheckBoost() : Check("Boost usage") {}
4842

4943
/** @brief Run checks against the normal token list */
50-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
51-
if (!tokenizer.isCPP())
52-
return;
53-
54-
CheckBoost checkBoost(&tokenizer, tokenizer.getSettings(), errorLogger);
55-
checkBoost.checkBoostForeachModification();
56-
}
57-
58-
/** @brief %Check for container modification while using the BOOST_FOREACH macro */
59-
void checkBoostForeachModification();
44+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
6045

6146
private:
62-
void boostForeachError(const Token *tok);
63-
64-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
65-
CheckBoost c(nullptr, settings, errorLogger);
66-
c.boostForeachError(nullptr);
67-
}
68-
69-
static std::string myName() {
70-
return "Boost usage";
71-
}
47+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
7248

7349
std::string classInfo() const override {
7450
return "Check for invalid usage of Boost:\n"

0 commit comments

Comments
 (0)