From 79d3f488dacf030d0d5033f487a55b0c68692c0c Mon Sep 17 00:00:00 2001 From: Ken-Patrick Lehrmann Date: Wed, 20 May 2020 14:56:55 +0200 Subject: [PATCH] Pass defines flags when calling clang (#2651) --- lib/cppcheck.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 03b95f86e..1fa6cf46d 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -233,6 +233,14 @@ static std::string executeAddon(const AddonInfo &addonInfo, return result; } +static std::string getDefinesFlags(const std::string &semicolonSeparatedString) +{ + std::string flags; + for (const std::string &d: split(semicolonSeparatedString, ";")) + flags += "-D" + d + " "; + return flags; +} + CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions, std::function,std::string,std::string*)> executeCommand) @@ -350,6 +358,9 @@ unsigned int CppCheck::check(const std::string &path) for (const std::string &i: mSettings.includePaths) flags += "-I" + i + " "; + flags += getDefinesFlags(mSettings.userDefines); + + const std::string args2 = "-cc1 -ast-dump " + flags + path; const std::string redirect2 = analyzerInfo.empty() ? std::string("2>&1") : ("2> " + clangStderr); if (!mSettings.buildDir.empty()) { @@ -1407,16 +1418,11 @@ void CppCheck::getErrorMessages() void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings) { std::string allIncludes = ""; - std::string allDefines = "-D"+fileSettings.defines; for (const std::string &inc : fileSettings.includePaths) { allIncludes = allIncludes + "-I\"" + inc + "\" "; } - std::string::size_type pos = 0u; - while ((pos = allDefines.find(";", pos)) != std::string::npos) { - allDefines.replace(pos, 1, " -D"); - pos += 3; - } + const std::string allDefines = getDefinesFlags(fileSettings.defines); #ifdef _WIN32 const char exe[] = "clang-tidy.exe";