3636#include < list>
3737#include < set>
3838#include < string>
39+ #include < utility>
3940#include < vector>
4041
4142#include < QByteArray>
@@ -61,7 +62,7 @@ static QString unquote(QString s) {
6162}
6263
6364// NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature
64- int CheckThread::executeCommand (std::string exe, std::vector<std::string> args, std::string redirect, std::string &output) // cppcheck-suppress passedByValue
65+ int CheckThread::executeCommand (std::string exe, std::vector<std::string> args, std::string redirect, std::string &output) // cppcheck-suppress [ passedByValue,passedByValueCallback]
6566{
6667 output.clear ();
6768
@@ -106,15 +107,13 @@ int CheckThread::executeCommand(std::string exe, std::vector<std::string> args,
106107
107108
108109CheckThread::CheckThread (ThreadResult &result) :
109- mResult(result),
110- mCppcheck(result, true , executeCommand)
110+ mResult(result)
111111{}
112112
113- void CheckThread::check (const Settings &settings)
113+ void CheckThread::setSettings (const Settings &settings)
114114{
115115 mFiles .clear ();
116- mCppcheck .settings () = settings;
117- start ();
116+ mSettings = settings; // this is a copy
118117}
119118
120119void CheckThread::analyseWholeProgram (const QStringList &files, const std::string& ctuInfo)
@@ -130,6 +129,9 @@ void CheckThread::run()
130129{
131130 mState = Running;
132131
132+ CppCheck cppcheck (mResult , true , executeCommand);
133+ cppcheck.settings () = std::move (mSettings );
134+
133135 if (!mFiles .isEmpty () || mAnalyseWholeProgram ) {
134136 mAnalyseWholeProgram = false ;
135137 std::string ctuInfo;
@@ -139,7 +141,7 @@ void CheckThread::run()
139141 std::transform (mFiles .cbegin (), mFiles .cend (), std::back_inserter (files2), [&](const QString& file) {
140142 return FileWithDetails{file.toStdString (), 0 };
141143 });
142- mCppcheck .analyseWholeProgram (mCppcheck .settings ().buildDir , files2, {}, ctuInfo);
144+ cppcheck .analyseWholeProgram (cppcheck .settings ().buildDir , files2, {}, ctuInfo);
143145 mFiles .clear ();
144146 emit done ();
145147 return ;
@@ -148,8 +150,8 @@ void CheckThread::run()
148150 QString file = mResult .getNextFile ();
149151 while (!file.isEmpty () && mState == Running) {
150152 qDebug () << " Checking file" << file;
151- mCppcheck .check (FileWithDetails (file.toStdString ()));
152- runAddonsAndTools (nullptr , file);
153+ cppcheck .check (FileWithDetails (file.toStdString ()));
154+ runAddonsAndTools (cppcheck. settings (), nullptr , file);
153155 emit fileChecked (file);
154156
155157 if (mState == Running)
@@ -161,8 +163,8 @@ void CheckThread::run()
161163 while (fileSettings && mState == Running) {
162164 file = QString::fromStdString (fileSettings->filename ());
163165 qDebug () << " Checking file" << file;
164- mCppcheck .check (*fileSettings);
165- runAddonsAndTools (fileSettings, QString::fromStdString (fileSettings->filename ()));
166+ cppcheck .check (*fileSettings);
167+ runAddonsAndTools (cppcheck. settings (), fileSettings, QString::fromStdString (fileSettings->filename ()));
166168 emit fileChecked (file);
167169
168170 if (mState == Running)
@@ -177,7 +179,7 @@ void CheckThread::run()
177179 emit done ();
178180}
179181
180- void CheckThread::runAddonsAndTools (const FileSettings *fileSettings, const QString &fileName)
182+ void CheckThread::runAddonsAndTools (const Settings& settings, const FileSettings *fileSettings, const QString &fileName)
181183{
182184 for (const QString& addon : mAddonsAndTools ) {
183185 if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) {
@@ -229,15 +231,15 @@ void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QStr
229231 args << (" -std=" + QString::fromStdString (fileSettings->standard ));
230232 else {
231233 // TODO: pass C or C++ standard based on file type
232- const std::string std = mCppcheck . settings () .standards .getCPP ();
234+ const std::string std = settings.standards .getCPP ();
233235 if (!std.empty ()) {
234236 args << (" -std=" + QString::fromStdString (std));
235237 }
236238 }
237239
238240 QString analyzerInfoFile;
239241
240- const std::string &buildDir = mCppcheck . settings () .buildDir ;
242+ const std::string &buildDir = settings.buildDir ;
241243 if (!buildDir.empty ()) {
242244 analyzerInfoFile = QString::fromStdString (AnalyzerInformation::getAnalyzerInfoFile (buildDir, fileSettings->filename (), fileSettings->cfg ));
243245
0 commit comments