Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ class CPPCHECKLIB Check {
/** This constructor is used when registering the CheckClass */
explicit Check(const std::string &aname);

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

public:
virtual ~Check() {
if (!mTokenizer)
instances().remove(this);
Expand Down Expand Up @@ -127,9 +129,9 @@ class CPPCHECKLIB Check {
return false;
}

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

protected:
const Tokenizer* const mTokenizer{};
const Settings* const mSettings{};
ErrorLogger* const mErrorLogger{};
Expand Down
5 changes: 3 additions & 2 deletions lib/check64bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ class Token;
*/

class CPPCHECKLIB Check64BitPortability : public Check {
friend class Test64BitPortability;

public:
/** This constructor is used when registering the Check64BitPortability */
Check64BitPortability() : Check(myName()) {}

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

private:

void assignmentAddressToIntegerError(const Token *tok);
void assignmentIntegerToAddressError(const Token *tok);
void returnIntegerError(const Token *tok);
Expand Down
5 changes: 3 additions & 2 deletions lib/checkassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class Token;
*/

class CPPCHECKLIB CheckAssert : public Check {
friend class TestFixture;

public:
CheckAssert() : Check(myName()) {}

private:
CheckAssert(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

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

void assertWithSideEffects();

protected:
void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope);
static bool inSameScope(const Token* returnTok, const Token* assignTok);

private:
void sideEffectInAssertError(const Token *tok, const std::string& functionName);
void assignmentInAssertError(const Token *tok, const std::string &varname);

Expand Down
4 changes: 3 additions & 1 deletion lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ namespace ValueFlow {


class CPPCHECKLIB CheckAutoVariables : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check(myName()) {}

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

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

private:
void errorAutoVariableAssignment(const Token *tok, bool inconclusive);
void errorReturnDanglingLifetime(const Token *tok, const ValueFlow::Value* val);
void errorInvalidLifetime(const Token *tok, const ValueFlow::Value* val);
Expand Down
4 changes: 3 additions & 1 deletion lib/checkbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ class Token;
/** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */

class CPPCHECKLIB CheckBool : public Check {
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckBool() : Check(myName()) {}

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

private:
// Error messages..
void comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression);
void comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2);
Expand Down
4 changes: 3 additions & 1 deletion lib/checkboost.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ class Token;

/** @brief %Check Boost usage */
class CPPCHECKLIB CheckBoost : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckBoost() : Check(myName()) {}

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

private:
void boostForeachError(const Token *tok);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
Expand Down
7 changes: 4 additions & 3 deletions lib/checkbufferoverrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ class Token;
* other function and pass a buffer and reads or writes too much data.
*/
class CPPCHECKLIB CheckBufferOverrun : public Check {
public:
friend class TestBufferOverrun;
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check(myName()) {}

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

private:

void arrayIndex();
void arrayIndexError(const Token* tok,
const std::vector<Dimension>& dimensions,
Expand Down
12 changes: 8 additions & 4 deletions lib/checkclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ namespace tinyxml2 {

/** @brief %Check classes. Uninitialized member variables, non-conforming operators, missing virtual destructor, etc */
class CPPCHECKLIB CheckClass : public Check {
friend class TestClass;
friend class TestConstructors;
friend class TestUnusedPrivateFunction;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckClass() : Check(myName()) {}

/** @brief Set of the STL types whose operator[] is not const */
static const std::set<std::string> stl_containers_not_const;

private:
/** @brief This constructor is used when running checks. */
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);

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

/** @brief Set of the STL types whose operator[] is not const */
static const std::set<std::string> stl_containers_not_const;

private:
const SymbolDatabase* mSymbolDatabase{};

// Reporting errors..
Expand Down
4 changes: 3 additions & 1 deletion lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ namespace ValueFlow {
*/

class CPPCHECKLIB CheckCondition : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckAssignIf */
CheckCondition() : Check(myName()) {}

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

private:
// The conditions that have been diagnosed
std::set<const Token*> mCondDiags;
bool diag(const Token* tok, bool insert=true);
Expand Down
4 changes: 3 additions & 1 deletion lib/checkexceptionsafety.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ class Token;
*/

class CPPCHECKLIB CheckExceptionSafety : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check(myName()) {}

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

private:
/** Don't throw exceptions in destructors */
void destructorsError(const Token * const tok, const std::string &className);
void deallocThrowError(const Token * const tok, const std::string &varname);
Expand Down
5 changes: 4 additions & 1 deletion lib/checkfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ namespace ValueFlow {
*/

class CPPCHECKLIB CheckFunctions : public Check {
friend class TestFunctions;
friend class TestFixture;

public:
/** This constructor is used when registering the CheckFunctions */
CheckFunctions() : Check(myName()) {}

private:
/** This constructor is used when running checks. */
CheckFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
Expand Down Expand Up @@ -109,7 +113,6 @@ class CPPCHECKLIB CheckFunctions : public Check {
/** @brief --check-library: warn for unconfigured function calls */
void checkLibraryMatchFunctions();

private:
/** @brief %Check for missing "return" */
void checkMissingReturn();

Expand Down
4 changes: 3 additions & 1 deletion lib/checkinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class Token;

/** @brief %Check Internal cppcheck API usage */
class CPPCHECKLIB CheckInternal : public Check {
friend class TestFixture;
public:
/** This constructor is used when registering the CheckClass */
CheckInternal() : Check(myName()) {}

private:
/** This constructor is used when running checks. */
CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
Expand Down Expand Up @@ -82,7 +84,7 @@ class CPPCHECKLIB CheckInternal : public Check {

/** @brief %Check if there is a redundant check for none-nullness of parameter before Match functions, such as (tok && Token::Match(tok, "foo")) */
void checkRedundantTokCheck();
private:

void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
Expand Down
4 changes: 3 additions & 1 deletion lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ class ErrorLogger;

/** @brief %Check input output operations. */
class CPPCHECKLIB CheckIO : public Check {
friend class TestIO;

public:
/** @brief This constructor is used when registering CheckIO */
CheckIO() : Check(myName()) {}

private:
/** @brief This constructor is used when running checks. */
CheckIO(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
Expand All @@ -70,7 +73,6 @@ class CPPCHECKLIB CheckIO : public Check {
/** @brief %Checks type and number of arguments given to functions like printf or scanf*/
void checkWrongPrintfScanfArguments();

private:
class ArgumentInfo {
public:
ArgumentInfo(const Token *arg, const Settings *settings, bool _isCPP);
Expand Down
5 changes: 3 additions & 2 deletions lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ class CPPCHECKLIB VarInfo {
*/

class CPPCHECKLIB CheckLeakAutoVar : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckLeakAutoVar */
CheckLeakAutoVar() : Check(myName()) {}

private:
/** This constructor is used when running checks. */
CheckLeakAutoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
Expand All @@ -120,8 +123,6 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check {
checkLeakAutoVar.check();
}

private:

/** check for leaks in all scopes */
void check();

Expand Down
Loading