clang-tidy: fix readability-make-member-function-const warnings

This commit is contained in:
Ben Boeckel 2021-01-22 10:37:38 -05:00
parent 4470eb5179
commit 808b17b120
37 changed files with 108 additions and 91 deletions

View File

@ -24,7 +24,6 @@ readability-*,\
-readability-implicit-bool-conversion,\
-readability-inconsistent-declaration-parameter-name,\
-readability-magic-numbers,\
-readability-make-member-function-const,\
-readability-named-parameter,\
-readability-qualified-auto,\
-readability-redundant-access-specifiers,\

View File

@ -44,7 +44,7 @@ bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const
: false;
}
bool cmCPackIFWCommon::IsVersionLess(const char* version)
bool cmCPackIFWCommon::IsVersionLess(const char* version) const
{
if (!this->Generator) {
return false;
@ -54,7 +54,7 @@ bool cmCPackIFWCommon::IsVersionLess(const char* version)
cmSystemTools::OP_LESS, this->Generator->FrameworkVersion.data(), version);
}
bool cmCPackIFWCommon::IsVersionGreater(const char* version)
bool cmCPackIFWCommon::IsVersionGreater(const char* version) const
{
if (!this->Generator) {
return false;
@ -65,7 +65,7 @@ bool cmCPackIFWCommon::IsVersionGreater(const char* version)
version);
}
bool cmCPackIFWCommon::IsVersionEqual(const char* version)
bool cmCPackIFWCommon::IsVersionEqual(const char* version) const
{
if (!this->Generator) {
return false;
@ -118,7 +118,7 @@ void cmCPackIFWCommon::ExpandListArgument(
}
}
void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout)
void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout) const
{
if (!this->Generator) {
return;

View File

@ -34,17 +34,17 @@ public:
/**
* Compare \a version with QtIFW framework version
*/
bool IsVersionLess(const char* version);
bool IsVersionLess(const char* version) const;
/**
* Compare \a version with QtIFW framework version
*/
bool IsVersionGreater(const char* version);
bool IsVersionGreater(const char* version) const;
/**
* Compare \a version with QtIFW framework version
*/
bool IsVersionEqual(const char* version);
bool IsVersionEqual(const char* version) const;
/** Expand the list argument containing the map of the key-value pairs.
* If the number of elements is odd, then the first value is used as the
@ -64,7 +64,7 @@ public:
cmCPackIFWGenerator* Generator;
protected:
void WriteGeneratedByToStrim(cmXMLWriter& xout);
void WriteGeneratedByToStrim(cmXMLWriter& xout) const;
};
#define cmCPackIFWLogger(logType, msg) \

View File

@ -199,7 +199,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml()
return cmSystemTools::RenameFile(updatesPatchXml, updatesXml);
}
void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout)
void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout) const
{
xout.StartElement("Repository");
@ -225,7 +225,7 @@ void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout)
xout.EndElement();
}
void cmCPackIFWRepository::WriteRepositoryUpdate(cmXMLWriter& xout)
void cmCPackIFWRepository::WriteRepositoryUpdate(cmXMLWriter& xout) const
{
xout.StartElement("Repository");

View File

@ -76,8 +76,8 @@ public:
bool PatchUpdatesXml();
void WriteRepositoryConfig(cmXMLWriter& xout);
void WriteRepositoryUpdate(cmXMLWriter& xout);
void WriteRepositoryConfig(cmXMLWriter& xout) const;
void WriteRepositoryUpdate(cmXMLWriter& xout) const;
void WriteRepositoryUpdates(cmXMLWriter& xout);
RepositoriesVector RepositoryUpdate;

View File

@ -107,7 +107,7 @@ public:
this->PipeState = cmsysProcess_WaitForExit(this->Process, timeout);
return this->PipeState;
}
int GetProcessState() { return this->PipeState; }
int GetProcessState() const { return this->PipeState; }
private:
int PipeState;

View File

@ -265,7 +265,7 @@ void cmCTestLaunch::LoadScrapeRules()
}
void cmCTestLaunch::LoadScrapeRules(
const char* purpose, std::vector<cmsys::RegularExpression>& regexps)
const char* purpose, std::vector<cmsys::RegularExpression>& regexps) const
{
std::string fname =
cmStrCat(this->Reporter.LogDir, "Custom", purpose, ".txt");

View File

@ -60,7 +60,7 @@ private:
bool ScrapeRulesLoaded;
void LoadScrapeRules();
void LoadScrapeRules(const char* purpose,
std::vector<cmsys::RegularExpression>& regexps);
std::vector<cmsys::RegularExpression>& regexps) const;
bool ScrapeLog(std::string const& fname);
// Helper class to generate the xml fragment.

View File

@ -150,7 +150,7 @@ void cmCTestLaunchReporter::WriteXML()
this->WriteXMLLabels(e2);
}
void cmCTestLaunchReporter::WriteXMLAction(cmXMLElement& e2)
void cmCTestLaunchReporter::WriteXMLAction(cmXMLElement& e2) const
{
e2.Comment("Meta-information about the build action");
cmXMLElement e3(e2, "Action");

View File

@ -70,7 +70,7 @@ public:
// Methods to generate the xml fragment.
void WriteXML();
void WriteXMLAction(cmXMLElement&);
void WriteXMLAction(cmXMLElement&) const;
void WriteXMLCommand(cmXMLElement&);
void WriteXMLResult(cmXMLElement&);
void WriteXMLLabels(cmXMLElement&);

View File

@ -300,7 +300,7 @@ void cmCTestMemCheckHandler::PopulateCustomVectors(cmMakefile* mf)
this->CustomTestsIgnore);
}
int cmCTestMemCheckHandler::GetDefectCount()
int cmCTestMemCheckHandler::GetDefectCount() const
{
return this->DefectCount;
}

View File

@ -29,7 +29,7 @@ public:
void Initialize() override;
int GetDefectCount();
int GetDefectCount() const;
protected:
int PreProcessHandler() override;

View File

@ -358,7 +358,7 @@ void cmProcess::ResetStartTime()
this->StartTime = std::chrono::steady_clock::now();
}
cmProcess::Exception cmProcess::GetExitException()
cmProcess::Exception cmProcess::GetExitException() const
{
auto exception = Exception::None;
#if defined(_WIN32) && !defined(__CYGWIN__)
@ -430,7 +430,7 @@ cmProcess::Exception cmProcess::GetExitException()
return exception;
}
std::string cmProcess::GetExitExceptionString()
std::string cmProcess::GetExitExceptionString() const
{
std::string exception_str;
#if defined(_WIN32)

View File

@ -67,8 +67,8 @@ public:
Other
};
Exception GetExitException();
std::string GetExitExceptionString();
Exception GetExitException() const;
std::string GetExitExceptionString() const;
std::unique_ptr<cmCTestRunTest> GetRunner()
{

View File

@ -951,6 +951,9 @@ void cmComputeLinkInformation::AddLinkExtension(std::string const& e,
}
}
// XXX(clang-tidy): This method's const-ness is platform dependent, so we
// cannot make it `const` as `clang-tidy` wants us to.
// NOLINTNEXTLINE(readability-make-member-function-const)
std::string cmComputeLinkInformation::CreateExtensionRegex(
std::vector<std::string> const& exts, LinkType type)
{

View File

@ -77,7 +77,7 @@ bool cmDepends::Check(const std::string& makeFile,
return okay;
}
void cmDepends::Clear(const std::string& file)
void cmDepends::Clear(const std::string& file) const
{
// Print verbose output.
if (this->Verbose) {

View File

@ -70,7 +70,7 @@ public:
DependencyMap& validDeps);
/** Clear dependencies for the target file so they will be regenerated. */
void Clear(const std::string& file);
void Clear(const std::string& file) const;
/** Set the file comparison object */
void SetFileTimeCache(cmFileTimeCache* fc) { this->FileTimeCache = fc; }

View File

@ -103,7 +103,7 @@ void cmDependsJavaParserHelper::SafePrintMissing(const char* str, int line,
std::cout << "- " << strlen(str) << std::endl;
}
}
void cmDependsJavaParserHelper::Print(const char* place, const char* str)
void cmDependsJavaParserHelper::Print(const char* place, const char* str) const
{
if (this->Verbose) {
std::cout << "[" << place << "=" << str << "]" << std::endl;

View File

@ -85,7 +85,7 @@ private:
void PrintClasses();
void Print(const char* place, const char* str);
void Print(const char* place, const char* str) const;
void CombineUnions(char** out, const char* in1, char** in2, const char* sep);
void SafePrintMissing(const char* str, int line, int cnt);

View File

@ -27,7 +27,7 @@ public:
void SetResult(KWIML_INT_int64_t value);
KWIML_INT_int64_t GetResult() { return this->Result; }
KWIML_INT_int64_t GetResult() const { return this->Result; }
const char* GetError() { return this->ErrorString.c_str(); }

View File

@ -57,7 +57,7 @@ private:
BOOL LockFile(DWORD flags);
#else
int File = -1;
int LockFile(int cmd, int type);
int LockFile(int cmd, int type) const;
#endif
std::string Filename;

View File

@ -64,7 +64,7 @@ cmFileLockResult cmFileLock::LockWithTimeout(unsigned long seconds)
}
}
int cmFileLock::LockFile(int cmd, int type)
int cmFileLock::LockFile(int cmd, int type) const
{
struct ::flock lock;
lock.l_start = 0;

View File

@ -80,8 +80,8 @@ std::string cmFindPathCommand::FindHeader()
return header;
}
std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file,
std::string const& dir)
std::string cmFindPathCommand::FindHeaderInFramework(
std::string const& file, std::string const& dir) const
{
std::string fileName = file;
std::string frameWorkName;

View File

@ -29,7 +29,7 @@ public:
private:
std::string FindHeaderInFramework(std::string const& file,
std::string const& dir);
std::string const& dir) const;
std::string FindHeader();
std::string FindNormalHeader(cmFindBaseDebugState& debug);
std::string FindFrameworkHeader(cmFindBaseDebugState& debug);

View File

@ -134,13 +134,13 @@ public:
std::set<std::string>& emitted);
// Make tool supports dependency files generated by compiler
bool SupportsCompilerDependencies()
bool SupportsCompilerDependencies() const
{
return this->ToolSupportsCompilerDependencies;
}
// Make tool supports long line dependencies
bool SupportsLongLineDependencies()
bool SupportsLongLineDependencies() const
{
return this->ToolSupportsLongLineDependencies;
}

View File

@ -57,28 +57,38 @@ public:
bool MakeFilesFullPath(const char* modeName,
const std::vector<std::string>& relFiles,
std::vector<std::string>& absFiles);
bool CheckCMP0006(bool& failure);
bool CheckCMP0006(bool& failure) const;
std::string GetDestination(const cmInstallCommandArguments* args,
const std::string& varName,
const std::string& guess);
std::string GetRuntimeDestination(const cmInstallCommandArguments* args);
std::string GetSbinDestination(const cmInstallCommandArguments* args);
std::string GetArchiveDestination(const cmInstallCommandArguments* args);
std::string GetLibraryDestination(const cmInstallCommandArguments* args);
std::string GetIncludeDestination(const cmInstallCommandArguments* args);
std::string GetSysconfDestination(const cmInstallCommandArguments* args);
std::string GetSharedStateDestination(const cmInstallCommandArguments* args);
std::string GetLocalStateDestination(const cmInstallCommandArguments* args);
std::string GetRunStateDestination(const cmInstallCommandArguments* args);
std::string GetDataRootDestination(const cmInstallCommandArguments* args);
std::string GetDataDestination(const cmInstallCommandArguments* args);
std::string GetInfoDestination(const cmInstallCommandArguments* args);
std::string GetLocaleDestination(const cmInstallCommandArguments* args);
std::string GetManDestination(const cmInstallCommandArguments* args);
std::string GetDocDestination(const cmInstallCommandArguments* args);
const std::string& guess) const;
std::string GetRuntimeDestination(
const cmInstallCommandArguments* args) const;
std::string GetSbinDestination(const cmInstallCommandArguments* args) const;
std::string GetArchiveDestination(
const cmInstallCommandArguments* args) const;
std::string GetLibraryDestination(
const cmInstallCommandArguments* args) const;
std::string GetIncludeDestination(
const cmInstallCommandArguments* args) const;
std::string GetSysconfDestination(
const cmInstallCommandArguments* args) const;
std::string GetSharedStateDestination(
const cmInstallCommandArguments* args) const;
std::string GetLocalStateDestination(
const cmInstallCommandArguments* args) const;
std::string GetRunStateDestination(
const cmInstallCommandArguments* args) const;
std::string GetDataRootDestination(
const cmInstallCommandArguments* args) const;
std::string GetDataDestination(const cmInstallCommandArguments* args) const;
std::string GetInfoDestination(const cmInstallCommandArguments* args) const;
std::string GetLocaleDestination(
const cmInstallCommandArguments* args) const;
std::string GetManDestination(const cmInstallCommandArguments* args) const;
std::string GetDocDestination(const cmInstallCommandArguments* args) const;
std::string GetDestinationForType(const cmInstallCommandArguments* args,
const std::string& type);
const std::string& type) const;
cmExecutionStatus& Status;
cmMakefile* Makefile;
@ -1477,7 +1487,7 @@ bool Helper::MakeFilesFullPath(const char* modeName,
return true;
}
bool Helper::CheckCMP0006(bool& failure)
bool Helper::CheckCMP0006(bool& failure) const
{
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
case cmPolicies::WARN:
@ -1504,7 +1514,7 @@ bool Helper::CheckCMP0006(bool& failure)
std::string Helper::GetDestination(const cmInstallCommandArguments* args,
const std::string& varName,
const std::string& guess)
const std::string& guess) const
{
if (args && !args->GetDestination().empty()) {
return args->GetDestination();
@ -1517,54 +1527,55 @@ std::string Helper::GetDestination(const cmInstallCommandArguments* args,
}
std::string Helper::GetRuntimeDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin");
}
std::string Helper::GetSbinDestination(const cmInstallCommandArguments* args)
std::string Helper::GetSbinDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin");
}
std::string Helper::GetArchiveDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
}
std::string Helper::GetLibraryDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
}
std::string Helper::GetIncludeDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include");
}
std::string Helper::GetSysconfDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc");
}
std::string Helper::GetSharedStateDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com");
}
std::string Helper::GetLocalStateDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var");
}
std::string Helper::GetRunStateDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR",
this->GetLocalStateDestination(nullptr) +
@ -1572,44 +1583,49 @@ std::string Helper::GetRunStateDestination(
}
std::string Helper::GetDataRootDestination(
const cmInstallCommandArguments* args)
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share");
}
std::string Helper::GetDataDestination(const cmInstallCommandArguments* args)
std::string Helper::GetDataDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_DATADIR",
this->GetDataRootDestination(nullptr));
}
std::string Helper::GetInfoDestination(const cmInstallCommandArguments* args)
std::string Helper::GetInfoDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_INFODIR",
this->GetDataRootDestination(nullptr) + "/info");
}
std::string Helper::GetLocaleDestination(const cmInstallCommandArguments* args)
std::string Helper::GetLocaleDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR",
this->GetDataRootDestination(nullptr) +
"/locale");
}
std::string Helper::GetManDestination(const cmInstallCommandArguments* args)
std::string Helper::GetManDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_MANDIR",
this->GetDataRootDestination(nullptr) + "/man");
}
std::string Helper::GetDocDestination(const cmInstallCommandArguments* args)
std::string Helper::GetDocDestination(
const cmInstallCommandArguments* args) const
{
return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR",
this->GetDataRootDestination(nullptr) + "/doc");
}
std::string Helper::GetDestinationForType(
const cmInstallCommandArguments* args, const std::string& type)
const cmInstallCommandArguments* args, const std::string& type) const
{
if (args && !args->GetDestination().empty()) {
return args->GetDestination();

View File

@ -53,9 +53,8 @@ bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
return true;
}
void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os,
Indent indent,
std::string const& script)
void cmInstallScriptGenerator::AddScriptInstallRule(
std::ostream& os, Indent indent, std::string const& script) const
{
if (this->Code) {
os << indent << script << "\n";

View File

@ -30,7 +30,7 @@ protected:
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
Indent indent) override;
void AddScriptInstallRule(std::ostream& os, Indent indent,
std::string const& script);
std::string const& script) const;
std::string const Script;
bool const Code;

View File

@ -30,7 +30,7 @@ struct cmListFileParser
bool ParseFunction(const char* name, long line);
bool AddArgument(cmListFileLexer_Token* token,
cmListFileArgument::Delimiter delim);
cm::optional<cmListFileContext> CheckNesting();
cm::optional<cmListFileContext> CheckNesting() const;
cmListFile* ListFile;
cmListFileBacktrace Backtrace;
cmMessenger* Messenger;
@ -352,7 +352,7 @@ bool TopIs(std::vector<NestingState>& stack, NestingStateEnum state)
}
}
cm::optional<cmListFileContext> cmListFileParser::CheckNesting()
cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
{
std::vector<NestingState> stack;

View File

@ -2772,7 +2772,7 @@ inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf,
void cmLocalGenerator::IncludeFileInUnitySources(
cmGeneratedFileStream& unity_file, std::string const& sf_full_path,
cmProp beforeInclude, cmProp afterInclude, cmProp uniqueIdName)
cmProp beforeInclude, cmProp afterInclude, cmProp uniqueIdName) const
{
if (uniqueIdName && !uniqueIdName->empty()) {
std::string pathToHash;

View File

@ -656,7 +656,7 @@ private:
void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
std::string const& sf_full_path,
cmProp beforeInclude, cmProp afterInclude,
cmProp uniqueIdName);
cmProp uniqueIdName) const;
std::vector<std::string> AddUnityFilesModeAuto(
cmGeneratorTarget* target, std::string const& lang,
std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,

View File

@ -23,7 +23,7 @@
#include "cmSystemTools.h"
std::string cmTimestamp::CurrentTime(const std::string& formatString,
bool utcFlag)
bool utcFlag) const
{
time_t currentTimeT = time(nullptr);
std::string source_date_epoch;
@ -45,7 +45,7 @@ std::string cmTimestamp::CurrentTime(const std::string& formatString,
std::string cmTimestamp::FileModificationTime(const char* path,
const std::string& formatString,
bool utcFlag)
bool utcFlag) const
{
std::string real_path =
cmSystemTools::GetRealPathResolvingWindowsSubst(path);

View File

@ -14,11 +14,11 @@
class cmTimestamp
{
public:
std::string CurrentTime(const std::string& formatString, bool utcFlag);
std::string CurrentTime(const std::string& formatString, bool utcFlag) const;
std::string FileModificationTime(const char* path,
const std::string& formatString,
bool utcFlag);
bool utcFlag) const;
std::string CreateTimestampFromTimeT(time_t timeT, std::string formatString,
bool utcFlag) const;

View File

@ -170,9 +170,9 @@ public:
private:
// -- Libuv callbacks
static void UVExit(uv_process_t* handle, int64_t exitStatus, int termSignal);
void UVPipeOutData(cmUVPipeBuffer::DataRange data);
void UVPipeOutData(cmUVPipeBuffer::DataRange data) const;
void UVPipeOutEnd(ssize_t error);
void UVPipeErrData(cmUVPipeBuffer::DataRange data);
void UVPipeErrData(cmUVPipeBuffer::DataRange data) const;
void UVPipeErrEnd(ssize_t error);
void UVTryFinish();
@ -330,7 +330,7 @@ void cmUVReadOnlyProcess::UVExit(uv_process_t* handle, int64_t exitStatus,
}
}
void cmUVReadOnlyProcess::UVPipeOutData(cmUVPipeBuffer::DataRange data)
void cmUVReadOnlyProcess::UVPipeOutData(cmUVPipeBuffer::DataRange data) const
{
this->Result()->StdOut.append(data.begin(), data.end());
}
@ -346,7 +346,7 @@ void cmUVReadOnlyProcess::UVPipeOutEnd(ssize_t error)
this->UVTryFinish();
}
void cmUVReadOnlyProcess::UVPipeErrData(cmUVPipeBuffer::DataRange data)
void cmUVReadOnlyProcess::UVPipeErrData(cmUVPipeBuffer::DataRange data) const
{
std::string* str = this->Setup_.MergedOutput ? &this->Result()->StdOut
: &this->Result()->StdErr;

View File

@ -28,7 +28,7 @@ cmXMLSafe& cmXMLSafe::Quotes(bool b)
return *this;
}
std::string cmXMLSafe::str()
std::string cmXMLSafe::str() const
{
std::ostringstream ss;
ss << *this;

View File

@ -24,7 +24,7 @@ public:
cmXMLSafe& Quotes(bool b = true);
/** Get the escaped data as a string. */
std::string str();
std::string str() const;
private:
char const* Data;

View File

@ -127,7 +127,7 @@ private:
exit(1);
}
bool IsWhitespace()
bool IsWhitespace() const
{
return (this->C == ' ' || this->C == '\t' || this->C == '\n' ||
this->C == '\r');