@@ -233,6 +233,14 @@ static std::string executeAddon(const AddonInfo &addonInfo,
233233 return result;
234234}
235235
236+ static std::string getDefinesFlags (const std::string &semicolonSeparatedString)
237+ {
238+ std::string flags;
239+ for (const std::string &d: split (semicolonSeparatedString, " ;" ))
240+ flags += " -D" + d + " " ;
241+ return flags;
242+ }
243+
236244CppCheck::CppCheck (ErrorLogger &errorLogger,
237245 bool useGlobalSuppressions,
238246 std::function<bool (std::string,std::vector<std::string>,std::string,std::string*)> executeCommand)
@@ -350,6 +358,9 @@ unsigned int CppCheck::check(const std::string &path)
350358 for (const std::string &i: mSettings .includePaths )
351359 flags += " -I" + i + " " ;
352360
361+ flags += getDefinesFlags (mSettings .userDefines );
362+
363+
353364 const std::string args2 = " -cc1 -ast-dump " + flags + path;
354365 const std::string redirect2 = analyzerInfo.empty () ? std::string (" 2>&1" ) : (" 2> " + clangStderr);
355366 if (!mSettings .buildDir .empty ()) {
@@ -1407,16 +1418,11 @@ void CppCheck::getErrorMessages()
14071418void CppCheck::analyseClangTidy (const ImportProject::FileSettings &fileSettings)
14081419{
14091420 std::string allIncludes = " " ;
1410- std::string allDefines = " -D" +fileSettings.defines ;
14111421 for (const std::string &inc : fileSettings.includePaths ) {
14121422 allIncludes = allIncludes + " -I\" " + inc + " \" " ;
14131423 }
14141424
1415- std::string::size_type pos = 0u ;
1416- while ((pos = allDefines.find (" ;" , pos)) != std::string::npos) {
1417- allDefines.replace (pos, 1 , " -D" );
1418- pos += 3 ;
1419- }
1425+ const std::string allDefines = getDefinesFlags (fileSettings.defines );
14201426
14211427#ifdef _WIN32
14221428 const char exe[] = " clang-tidy.exe" ;
0 commit comments