adjusted tests to reduce the amount of `friend` declarations necessary (#5435)

We were calling several interface functions through their inherited
classes instead of using the base classes requiring us to add `friend`
declarations to make the implementations accessible. This adjusts
several of those cases.
This commit is contained in:
Oliver Stöneberg 2023-09-11 20:26:22 +02:00 committed by GitHub
parent b31860b72d
commit e7dd490fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 20 additions and 56 deletions

View File

@ -41,8 +41,6 @@ class Token;
*/ */
class CPPCHECKLIB CheckAssert : public Check { class CPPCHECKLIB CheckAssert : public Check {
friend class TestFixture;
public: public:
CheckAssert() : Check(myName()) {} CheckAssert() : Check(myName()) {}

View File

@ -45,8 +45,6 @@ namespace ValueFlow {
class CPPCHECKLIB CheckAutoVariables : public Check { class CPPCHECKLIB CheckAutoVariables : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check(myName()) {} CheckAutoVariables() : Check(myName()) {}

View File

@ -39,8 +39,6 @@ class Token;
/** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */ /** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */
class CPPCHECKLIB CheckBool : public Check { class CPPCHECKLIB CheckBool : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckBool() : Check(myName()) {} CheckBool() : Check(myName()) {}

View File

@ -38,8 +38,6 @@ class Token;
/** @brief %Check Boost usage */ /** @brief %Check Boost usage */
class CPPCHECKLIB CheckBoost : public Check { class CPPCHECKLIB CheckBoost : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBoost() : Check(myName()) {} CheckBoost() : Check(myName()) {}

View File

@ -57,9 +57,6 @@ class Token;
* other function and pass a buffer and reads or writes too much data. * other function and pass a buffer and reads or writes too much data.
*/ */
class CPPCHECKLIB CheckBufferOverrun : public Check { class CPPCHECKLIB CheckBufferOverrun : public Check {
friend class TestBufferOverrun;
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check(myName()) {} CheckBufferOverrun() : Check(myName()) {}

View File

@ -48,8 +48,6 @@ namespace ValueFlow {
*/ */
class CPPCHECKLIB CheckCondition : public Check { class CPPCHECKLIB CheckCondition : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckAssignIf */ /** This constructor is used when registering the CheckAssignIf */
CheckCondition() : Check(myName()) {} CheckCondition() : Check(myName()) {}

View File

@ -45,8 +45,6 @@ class Token;
*/ */
class CPPCHECKLIB CheckExceptionSafety : public Check { class CPPCHECKLIB CheckExceptionSafety : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check(myName()) {} CheckExceptionSafety() : Check(myName()) {}

View File

@ -49,9 +49,6 @@ namespace ValueFlow {
*/ */
class CPPCHECKLIB CheckFunctions : public Check { class CPPCHECKLIB CheckFunctions : public Check {
friend class TestFunctions;
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckFunctions */ /** This constructor is used when registering the CheckFunctions */
CheckFunctions() : Check(myName()) {} CheckFunctions() : Check(myName()) {}

View File

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

View File

@ -107,8 +107,6 @@ public:
*/ */
class CPPCHECKLIB CheckLeakAutoVar : public Check { class CPPCHECKLIB CheckLeakAutoVar : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckLeakAutoVar */ /** This constructor is used when registering the CheckLeakAutoVar */
CheckLeakAutoVar() : Check(myName()) {} CheckLeakAutoVar() : Check(myName()) {}

View File

@ -48,7 +48,6 @@ namespace tinyxml2 {
class CPPCHECKLIB CheckNullPointer : public Check { class CPPCHECKLIB CheckNullPointer : public Check {
friend class TestNullPointer; friend class TestNullPointer;
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckNullPointer */ /** @brief This constructor is used when registering the CheckNullPointer */

View File

@ -50,7 +50,6 @@ class CPPCHECKLIB CheckOther : public Check {
friend class TestCharVar; friend class TestCharVar;
friend class TestIncompleteStatement; friend class TestIncompleteStatement;
friend class TestOther; friend class TestOther;
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */

View File

@ -39,8 +39,6 @@ class Token;
/** @brief checks on usage of sizeof() operator */ /** @brief checks on usage of sizeof() operator */
class CPPCHECKLIB CheckSizeof : public Check { class CPPCHECKLIB CheckSizeof : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckSizeof() : Check(myName()) {} CheckSizeof() : Check(myName()) {}

View File

@ -43,8 +43,6 @@ class ErrorLogger;
/** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */ /** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */
class CPPCHECKLIB CheckStl : public Check { class CPPCHECKLIB CheckStl : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckStl() : Check(myName()) {} CheckStl() : Check(myName()) {}

View File

@ -39,8 +39,6 @@ class Token;
/** @brief Detect misusage of C-style strings and related standard functions */ /** @brief Detect misusage of C-style strings and related standard functions */
class CPPCHECKLIB CheckString : public Check { class CPPCHECKLIB CheckString : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckString() : Check(myName()) {} CheckString() : Check(myName()) {}

View File

@ -42,8 +42,6 @@ class ValueType;
/** @brief Various small checks */ /** @brief Various small checks */
class CPPCHECKLIB CheckType : public Check { class CPPCHECKLIB CheckType : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckType() : Check(myName()) {} CheckType() : Check(myName()) {}

View File

@ -44,8 +44,6 @@ namespace CTU {
/// @{ /// @{
class CPPCHECKLIB CheckUnusedFunctions : public Check { class CPPCHECKLIB CheckUnusedFunctions : public Check {
friend class TestUnusedFunctions;
public: public:
/** @brief This constructor is used when registering the CheckUnusedFunctions */ /** @brief This constructor is used when registering the CheckUnusedFunctions */
CheckUnusedFunctions() : Check(myName()) {} CheckUnusedFunctions() : Check(myName()) {}

View File

@ -40,8 +40,6 @@ class Token;
*/ */
class CPPCHECKLIB CheckVaarg : public Check { class CPPCHECKLIB CheckVaarg : public Check {
friend class TestFixture;
public: public:
CheckVaarg() : Check(myName()) {} CheckVaarg() : Check(myName()) {}

View File

@ -127,7 +127,7 @@ protected:
template<typename T> template<typename T>
static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{ {
T& check = getCheck<T>(); Check& check = getCheck<T>();
check.runChecks(tokenizer, errorLogger); check.runChecks(tokenizer, errorLogger);
} }

View File

@ -4966,7 +4966,8 @@ private:
void getErrorMessages() { void getErrorMessages() {
// Ticket #2292: segmentation fault when using --errorlist // Ticket #2292: segmentation fault when using --errorlist
getCheck<CheckBufferOverrun>().getErrorMessages(this, nullptr); const Check& c = getCheck<CheckBufferOverrun>();
c.getErrorMessages(this, nullptr);
} }
void arrayIndexThenCheck() { void arrayIndexThenCheck() {
@ -5161,9 +5162,9 @@ private:
// Check code.. // Check code..
std::list<Check::FileInfo*> fileInfo; std::list<Check::FileInfo*> fileInfo;
CheckBufferOverrun checkBO(&tokenizer, &settings0, this); Check& c = getCheck<CheckBufferOverrun>();
fileInfo.push_back(checkBO.getFileInfo(&tokenizer, &settings0)); fileInfo.push_back(c.getFileInfo(&tokenizer, &settings0));
checkBO.analyseWholeProgram(ctu, fileInfo, settings0, *this); c.analyseWholeProgram(ctu, fileInfo, settings0, *this);
while (!fileInfo.empty()) { while (!fileInfo.empty()) {
delete fileInfo.back(); delete fileInfo.back();
fileInfo.pop_back(); fileInfo.pop_back();

View File

@ -8777,7 +8777,7 @@ private:
void ctu(const std::vector<std::string> &code) { void ctu(const std::vector<std::string> &code) {
const Settings settings; const Settings settings;
auto &check = getCheck<CheckClass>(); Check &check = getCheck<CheckClass>();
// getFileInfo // getFileInfo
std::list<Check::FileInfo*> fileInfo; std::list<Check::FileInfo*> fileInfo;
@ -8835,9 +8835,8 @@ private:
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
// Check.. // Check..
CheckClass checkClass(&tokenizer, &settings1, this); const Check& c = getCheck<CheckClass>();
Check::FileInfo * fileInfo = (c.getFileInfo)(&tokenizer, &settings1);
Check::FileInfo * fileInfo = (checkClass.getFileInfo)(&tokenizer, &settings1);
delete fileInfo; delete fileInfo;
} }

View File

@ -102,13 +102,12 @@ private:
ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line); ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line);
// Check.. // Check..
CheckIO checkIO(&tokenizer, &settings1, this); if (onlyFormatStr) {
checkIO.checkWrongPrintfScanfArguments(); CheckIO checkIO(&tokenizer, &settings1, this);
if (!onlyFormatStr) { checkIO.checkWrongPrintfScanfArguments();
checkIO.checkCoutCerrMisusage(); return;
checkIO.checkFileUsage();
checkIO.invalidScanf();
} }
runChecks<CheckIO>(tokenizer, this);
} }
void coutCerrMisusage() { void coutCerrMisusage() {

View File

@ -4412,9 +4412,9 @@ private:
// Check code.. // Check code..
std::list<Check::FileInfo*> fileInfo; std::list<Check::FileInfo*> fileInfo;
CheckNullPointer checkNullPointer(&tokenizer, &settings, this); Check& c = getCheck<CheckNullPointer>();
fileInfo.push_back(checkNullPointer.getFileInfo(&tokenizer, &settings)); fileInfo.push_back(c.getFileInfo(&tokenizer, &settings));
checkNullPointer.analyseWholeProgram(ctu, fileInfo, settings, *this); c.analyseWholeProgram(ctu, fileInfo, settings, *this);
while (!fileInfo.empty()) { while (!fileInfo.empty()) {
delete fileInfo.back(); delete fileInfo.back();
fileInfo.pop_back(); fileInfo.pop_back();

View File

@ -7371,9 +7371,9 @@ private:
// Check code.. // Check code..
std::list<Check::FileInfo*> fileInfo; std::list<Check::FileInfo*> fileInfo;
CheckUninitVar check(&tokenizer, &settings, this); Check& c = getCheck<CheckUninitVar>();
fileInfo.push_back(check.getFileInfo(&tokenizer, &settings)); fileInfo.push_back(c.getFileInfo(&tokenizer, &settings));
check.analyseWholeProgram(ctu, fileInfo, settings, *this); c.analyseWholeProgram(ctu, fileInfo, settings, *this);
while (!fileInfo.empty()) { while (!fileInfo.empty()) {
delete fileInfo.back(); delete fileInfo.back();
fileInfo.pop_back(); fileInfo.pop_back();