Skip to content

Commit bbe45ff

Browse files
authored
cleaned up access of the check classes (#5387)
1 parent 64cd09a commit bbe45ff

27 files changed

Lines changed: 144 additions & 83 deletions

lib/check.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ class CPPCHECKLIB Check {
6161
/** This constructor is used when registering the CheckClass */
6262
explicit Check(const std::string &aname);
6363

64+
protected:
6465
/** This constructor is used when running checks. */
6566
Check(std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
6667
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mName(std::move(aname)) {}
6768

69+
public:
6870
virtual ~Check() {
6971
if (!mTokenizer)
7072
instances().remove(this);
@@ -127,9 +129,9 @@ class CPPCHECKLIB Check {
127129
return false;
128130
}
129131

132+
protected:
130133
static std::string getMessageId(const ValueFlow::Value &value, const char id[]);
131134

132-
protected:
133135
const Tokenizer* const mTokenizer{};
134136
const Settings* const mSettings{};
135137
ErrorLogger* const mErrorLogger{};

lib/check64bit.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ class Token;
4141
*/
4242

4343
class CPPCHECKLIB Check64BitPortability : public Check {
44+
friend class Test64BitPortability;
45+
4446
public:
4547
/** This constructor is used when registering the Check64BitPortability */
4648
Check64BitPortability() : Check(myName()) {}
4749

50+
private:
4851
/** This constructor is used when running checks. */
4952
Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
5053
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -58,8 +61,6 @@ class CPPCHECKLIB Check64BitPortability : public Check {
5861
/** Check for pointer assignment */
5962
void pointerassignment();
6063

61-
private:
62-
6364
void assignmentAddressToIntegerError(const Token *tok);
6465
void assignmentIntegerToAddressError(const Token *tok);
6566
void returnIntegerError(const Token *tok);

lib/checkassert.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ class Token;
4141
*/
4242

4343
class CPPCHECKLIB CheckAssert : public Check {
44+
friend class TestFixture;
45+
4446
public:
4547
CheckAssert() : Check(myName()) {}
4648

49+
private:
4750
CheckAssert(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
4851
: Check(myName(), tokenizer, settings, errorLogger) {}
4952

@@ -55,11 +58,9 @@ class CPPCHECKLIB CheckAssert : public Check {
5558

5659
void assertWithSideEffects();
5760

58-
protected:
5961
void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope);
6062
static bool inSameScope(const Token* returnTok, const Token* assignTok);
6163

62-
private:
6364
void sideEffectInAssertError(const Token *tok, const std::string& functionName);
6465
void assignmentInAssertError(const Token *tok, const std::string &varname);
6566

lib/checkautovariables.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ namespace ValueFlow {
4545

4646

4747
class CPPCHECKLIB CheckAutoVariables : public Check {
48+
friend class TestFixture;
49+
4850
public:
4951
/** This constructor is used when registering the CheckClass */
5052
CheckAutoVariables() : Check(myName()) {}
5153

54+
private:
5255
/** This constructor is used when running checks. */
5356
CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
5457
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -76,7 +79,6 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
7679

7780
void checkVarLifetimeScope(const Token * start, const Token * end);
7881

79-
private:
8082
void errorAutoVariableAssignment(const Token *tok, bool inconclusive);
8183
void errorReturnDanglingLifetime(const Token *tok, const ValueFlow::Value* val);
8284
void errorInvalidLifetime(const Token *tok, const ValueFlow::Value* val);

lib/checkbool.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ class Token;
3939
/** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */
4040

4141
class CPPCHECKLIB CheckBool : public Check {
42+
friend class TestFixture;
43+
4244
public:
4345
/** @brief This constructor is used when registering the CheckClass */
4446
CheckBool() : Check(myName()) {}
4547

48+
private:
4649
/** @brief This constructor is used when running checks. */
4750
CheckBool(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
4851
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -95,7 +98,6 @@ class CPPCHECKLIB CheckBool : public Check {
9598
/** @brief %Check if a function returning bool returns an integer other than 0 or 1 */
9699
void returnValueOfFunctionReturningBool();
97100

98-
private:
99101
// Error messages..
100102
void comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression);
101103
void comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2);

lib/checkboost.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ class Token;
3838

3939
/** @brief %Check Boost usage */
4040
class CPPCHECKLIB CheckBoost : public Check {
41+
friend class TestFixture;
42+
4143
public:
4244
/** This constructor is used when registering the CheckClass */
4345
CheckBoost() : Check(myName()) {}
4446

47+
private:
4548
/** This constructor is used when running checks. */
4649
CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
4750
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -58,7 +61,6 @@ class CPPCHECKLIB CheckBoost : public Check {
5861
/** @brief %Check for container modification while using the BOOST_FOREACH macro */
5962
void checkBoostForeachModification();
6063

61-
private:
6264
void boostForeachError(const Token *tok);
6365

6466
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {

lib/checkbufferoverrun.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ class Token;
5757
* other function and pass a buffer and reads or writes too much data.
5858
*/
5959
class CPPCHECKLIB CheckBufferOverrun : public Check {
60-
public:
60+
friend class TestBufferOverrun;
61+
friend class TestFixture;
6162

63+
public:
6264
/** This constructor is used when registering the CheckClass */
6365
CheckBufferOverrun() : Check(myName()) {}
6466

67+
private:
6568
/** This constructor is used when running checks. */
6669
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
6770
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -97,8 +100,6 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
97100
/** @brief Analyse all file infos for all TU */
98101
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
99102

100-
private:
101-
102103
void arrayIndex();
103104
void arrayIndexError(const Token* tok,
104105
const std::vector<Dimension>& dimensions,

lib/checkclass.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ namespace tinyxml2 {
5151

5252
/** @brief %Check classes. Uninitialized member variables, non-conforming operators, missing virtual destructor, etc */
5353
class CPPCHECKLIB CheckClass : public Check {
54+
friend class TestClass;
55+
friend class TestConstructors;
56+
friend class TestUnusedPrivateFunction;
57+
5458
public:
5559
/** @brief This constructor is used when registering the CheckClass */
5660
CheckClass() : Check(myName()) {}
5761

62+
/** @brief Set of the STL types whose operator[] is not const */
63+
static const std::set<std::string> stl_containers_not_const;
64+
65+
private:
5866
/** @brief This constructor is used when running checks. */
5967
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
6068

@@ -191,10 +199,6 @@ class CPPCHECKLIB CheckClass : public Check {
191199
/** @brief Analyse all file infos for all TU */
192200
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
193201

194-
/** @brief Set of the STL types whose operator[] is not const */
195-
static const std::set<std::string> stl_containers_not_const;
196-
197-
private:
198202
const SymbolDatabase* mSymbolDatabase{};
199203

200204
// Reporting errors..

lib/checkcondition.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ namespace ValueFlow {
4848
*/
4949

5050
class CPPCHECKLIB CheckCondition : public Check {
51+
friend class TestFixture;
52+
5153
public:
5254
/** This constructor is used when registering the CheckAssignIf */
5355
CheckCondition() : Check(myName()) {}
5456

57+
private:
5558
/** This constructor is used when running checks. */
5659
CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
5760
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -128,7 +131,6 @@ class CPPCHECKLIB CheckCondition : public Check {
128131
/** @brief Assignment in condition */
129132
void checkAssignmentInCondition();
130133

131-
private:
132134
// The conditions that have been diagnosed
133135
std::set<const Token*> mCondDiags;
134136
bool diag(const Token* tok, bool insert=true);

lib/checkexceptionsafety.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ class Token;
4545
*/
4646

4747
class CPPCHECKLIB CheckExceptionSafety : public Check {
48+
friend class TestFixture;
49+
4850
public:
4951
/** This constructor is used when registering the CheckClass */
5052
CheckExceptionSafety() : Check(myName()) {}
5153

54+
private:
5255
/** This constructor is used when running checks. */
5356
CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
5457
: Check(myName(), tokenizer, settings, errorLogger) {}
@@ -88,7 +91,6 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
8891
/** @brief %Check for rethrow not from catch scope */
8992
void rethrowNoCurrentException();
9093

91-
private:
9294
/** Don't throw exceptions in destructors */
9395
void destructorsError(const Token * const tok, const std::string &className);
9496
void deallocThrowError(const Token * const tok, const std::string &varname);

0 commit comments

Comments
 (0)