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 {
friend class TestFixture;
public:
CheckAssert() : Check(myName()) {}

View File

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

View File

@ -39,8 +39,6 @@ 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()) {}

View File

@ -38,8 +38,6 @@ 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()) {}

View File

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

View File

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

View File

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

View File

@ -49,9 +49,6 @@ 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()) {}

View File

@ -39,7 +39,6 @@ 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()) {}

View File

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

View File

@ -48,7 +48,6 @@ namespace tinyxml2 {
class CPPCHECKLIB CheckNullPointer : public Check {
friend class TestNullPointer;
friend class TestFixture;
public:
/** @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 TestIncompleteStatement;
friend class TestOther;
friend class TestFixture;
public:
/** @brief This constructor is used when registering the CheckClass */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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