forked from qt-creator/qt-creator
CppTools: Fix MSVC toolchain flags for C-files
In case of C-header or C-source files the MSVC language version was not switched to C. Fixes static analyzer runs for C files. Task-number: QTCREATORBUG-20198 Change-Id: I1da31a1048b7c258642cf00f5084681f5d384ee6 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -47,6 +47,7 @@ CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||
: m_projectPart(projectPart)
|
||||
, m_clangVersion(clangVersion)
|
||||
, m_clangResourceDirectory(clangResourceDirectory)
|
||||
, m_languageVersion(m_projectPart.languageVersion)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -54,6 +55,9 @@ QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
|
||||
{
|
||||
m_options.clear();
|
||||
|
||||
if (fileKind == ProjectFile::CHeader || fileKind == ProjectFile::CSource)
|
||||
QTC_ASSERT(m_languageVersion <= ProjectPart::LatestCVersion, return QStringList(););
|
||||
|
||||
addWordWidth();
|
||||
addTargetTriple();
|
||||
addExtraCodeModelFlags();
|
||||
@@ -119,6 +123,7 @@ void CompilerOptionsBuilder::addExtraCodeModelFlags()
|
||||
|
||||
void CompilerOptionsBuilder::enableExceptions()
|
||||
{
|
||||
if (m_languageVersion > ProjectPart::LatestCVersion)
|
||||
add(QLatin1String("-fcxx-exceptions"));
|
||||
add(QLatin1String("-fexceptions"));
|
||||
}
|
||||
@@ -287,7 +292,8 @@ void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtension
|
||||
QStringList opts;
|
||||
const ProjectPart::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
||||
const bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions;
|
||||
switch (m_projectPart.languageVersion) {
|
||||
|
||||
switch (m_languageVersion) {
|
||||
case ProjectPart::C89:
|
||||
opts << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
||||
break;
|
||||
@@ -472,9 +478,7 @@ QString CompilerOptionsBuilder::includeOption() const
|
||||
|
||||
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
||||
{
|
||||
// This is a quick fix for QTCREATORBUG-11501.
|
||||
// TODO: do a proper fix, see QTCREATORBUG-11709.
|
||||
if (macro.key == "__cplusplus")
|
||||
if (macro.key == "__cplusplus" && m_languageVersion <= ProjectPart::LatestCVersion)
|
||||
return true;
|
||||
|
||||
// Ignore for all compiler toolchains since LLVM has it's own implementation for
|
||||
|
@@ -96,6 +96,7 @@ private:
|
||||
QStringList m_options;
|
||||
QString m_clangVersion;
|
||||
QString m_clangResourceDirectory;
|
||||
ProjectPart::LanguageVersion m_languageVersion;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
@@ -133,15 +133,27 @@ ToolChain::CompilerFlags AbstractMsvcToolChain::compilerFlags(const QStringList
|
||||
if (cxxflags.contains(QLatin1String("/Za")))
|
||||
flags &= ~MicrosoftExtensions;
|
||||
|
||||
bool cLanguage = (language() == ProjectExplorer::Constants::C_LANGUAGE_ID);
|
||||
|
||||
switch (m_abi.osFlavor()) {
|
||||
case Abi::WindowsMsvc2010Flavor:
|
||||
case Abi::WindowsMsvc2012Flavor: flags |= StandardCxx11;
|
||||
case Abi::WindowsMsvc2012Flavor:
|
||||
if (cLanguage)
|
||||
flags |= StandardC99;
|
||||
else
|
||||
flags |= StandardCxx11;
|
||||
break;
|
||||
case Abi::WindowsMsvc2013Flavor:
|
||||
case Abi::WindowsMsvc2015Flavor: flags |= StandardCxx14;
|
||||
case Abi::WindowsMsvc2015Flavor:
|
||||
if (cLanguage)
|
||||
flags |= StandardC99;
|
||||
else
|
||||
flags |= StandardCxx14;
|
||||
break;
|
||||
case Abi::WindowsMsvc2017Flavor:
|
||||
if (cxxflags.contains("/std:c++17") || cxxflags.contains("/std:c++latest"))
|
||||
if (cLanguage)
|
||||
flags |= StandardC11;
|
||||
else if (cxxflags.contains("/std:c++17") || cxxflags.contains("/std:c++latest"))
|
||||
flags |= StandardCxx17;
|
||||
else
|
||||
flags |= StandardCxx14;
|
||||
|
Reference in New Issue
Block a user