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_projectPart(projectPart)
|
||||||
, m_clangVersion(clangVersion)
|
, m_clangVersion(clangVersion)
|
||||||
, m_clangResourceDirectory(clangResourceDirectory)
|
, m_clangResourceDirectory(clangResourceDirectory)
|
||||||
|
, m_languageVersion(m_projectPart.languageVersion)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +55,9 @@ QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
|
|||||||
{
|
{
|
||||||
m_options.clear();
|
m_options.clear();
|
||||||
|
|
||||||
|
if (fileKind == ProjectFile::CHeader || fileKind == ProjectFile::CSource)
|
||||||
|
QTC_ASSERT(m_languageVersion <= ProjectPart::LatestCVersion, return QStringList(););
|
||||||
|
|
||||||
addWordWidth();
|
addWordWidth();
|
||||||
addTargetTriple();
|
addTargetTriple();
|
||||||
addExtraCodeModelFlags();
|
addExtraCodeModelFlags();
|
||||||
@@ -119,7 +123,8 @@ void CompilerOptionsBuilder::addExtraCodeModelFlags()
|
|||||||
|
|
||||||
void CompilerOptionsBuilder::enableExceptions()
|
void CompilerOptionsBuilder::enableExceptions()
|
||||||
{
|
{
|
||||||
add(QLatin1String("-fcxx-exceptions"));
|
if (m_languageVersion > ProjectPart::LatestCVersion)
|
||||||
|
add(QLatin1String("-fcxx-exceptions"));
|
||||||
add(QLatin1String("-fexceptions"));
|
add(QLatin1String("-fexceptions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +292,8 @@ void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtension
|
|||||||
QStringList opts;
|
QStringList opts;
|
||||||
const ProjectPart::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
const ProjectPart::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
||||||
const bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions;
|
const bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions;
|
||||||
switch (m_projectPart.languageVersion) {
|
|
||||||
|
switch (m_languageVersion) {
|
||||||
case ProjectPart::C89:
|
case ProjectPart::C89:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
opts << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
||||||
break;
|
break;
|
||||||
@@ -472,9 +478,7 @@ QString CompilerOptionsBuilder::includeOption() const
|
|||||||
|
|
||||||
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
||||||
{
|
{
|
||||||
// This is a quick fix for QTCREATORBUG-11501.
|
if (macro.key == "__cplusplus" && m_languageVersion <= ProjectPart::LatestCVersion)
|
||||||
// TODO: do a proper fix, see QTCREATORBUG-11709.
|
|
||||||
if (macro.key == "__cplusplus")
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Ignore for all compiler toolchains since LLVM has it's own implementation for
|
// Ignore for all compiler toolchains since LLVM has it's own implementation for
|
||||||
|
@@ -96,6 +96,7 @@ private:
|
|||||||
QStringList m_options;
|
QStringList m_options;
|
||||||
QString m_clangVersion;
|
QString m_clangVersion;
|
||||||
QString m_clangResourceDirectory;
|
QString m_clangResourceDirectory;
|
||||||
|
ProjectPart::LanguageVersion m_languageVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@@ -133,15 +133,27 @@ ToolChain::CompilerFlags AbstractMsvcToolChain::compilerFlags(const QStringList
|
|||||||
if (cxxflags.contains(QLatin1String("/Za")))
|
if (cxxflags.contains(QLatin1String("/Za")))
|
||||||
flags &= ~MicrosoftExtensions;
|
flags &= ~MicrosoftExtensions;
|
||||||
|
|
||||||
|
bool cLanguage = (language() == ProjectExplorer::Constants::C_LANGUAGE_ID);
|
||||||
|
|
||||||
switch (m_abi.osFlavor()) {
|
switch (m_abi.osFlavor()) {
|
||||||
case Abi::WindowsMsvc2010Flavor:
|
case Abi::WindowsMsvc2010Flavor:
|
||||||
case Abi::WindowsMsvc2012Flavor: flags |= StandardCxx11;
|
case Abi::WindowsMsvc2012Flavor:
|
||||||
|
if (cLanguage)
|
||||||
|
flags |= StandardC99;
|
||||||
|
else
|
||||||
|
flags |= StandardCxx11;
|
||||||
break;
|
break;
|
||||||
case Abi::WindowsMsvc2013Flavor:
|
case Abi::WindowsMsvc2013Flavor:
|
||||||
case Abi::WindowsMsvc2015Flavor: flags |= StandardCxx14;
|
case Abi::WindowsMsvc2015Flavor:
|
||||||
|
if (cLanguage)
|
||||||
|
flags |= StandardC99;
|
||||||
|
else
|
||||||
|
flags |= StandardCxx14;
|
||||||
break;
|
break;
|
||||||
case Abi::WindowsMsvc2017Flavor:
|
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;
|
flags |= StandardCxx17;
|
||||||
else
|
else
|
||||||
flags |= StandardCxx14;
|
flags |= StandardCxx14;
|
||||||
|
Reference in New Issue
Block a user