forked from qt-creator/qt-creator
Clang: Undefine language features as fix for MSVC2015/clang-3.8.0
This applies the following change for the clang code model, too.
commit d13d179524
Clang Static Analyzer: Workaround analyzing MSVC2015 projects with clang 3.8.0 II
Change-Id: Ia229d7e8b24c2e1c0a83d9a53c623ea1f79c4a06
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -283,6 +283,55 @@ void CompilerOptionsBuilder::addMsvcCompatibilityVersion()
|
||||
}
|
||||
}
|
||||
|
||||
static QStringList languageFeatureMacros()
|
||||
{
|
||||
// Collected with:
|
||||
// $ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
|
||||
// $ D:\usr\llvm-3.8.0\bin\clang++.exe -fms-compatibility-version=19 -std=c++1y -dM -E D:\empty.cpp | grep __cpp_
|
||||
static QStringList macros {
|
||||
QLatin1String("__cpp_aggregate_nsdmi"),
|
||||
QLatin1String("__cpp_alias_templates"),
|
||||
QLatin1String("__cpp_attributes"),
|
||||
QLatin1String("__cpp_binary_literals"),
|
||||
QLatin1String("__cpp_constexpr"),
|
||||
QLatin1String("__cpp_decltype"),
|
||||
QLatin1String("__cpp_decltype_auto"),
|
||||
QLatin1String("__cpp_delegating_constructors"),
|
||||
QLatin1String("__cpp_digit_separators"),
|
||||
QLatin1String("__cpp_generic_lambdas"),
|
||||
QLatin1String("__cpp_inheriting_constructors"),
|
||||
QLatin1String("__cpp_init_captures"),
|
||||
QLatin1String("__cpp_initializer_lists"),
|
||||
QLatin1String("__cpp_lambdas"),
|
||||
QLatin1String("__cpp_nsdmi"),
|
||||
QLatin1String("__cpp_range_based_for"),
|
||||
QLatin1String("__cpp_raw_strings"),
|
||||
QLatin1String("__cpp_ref_qualifiers"),
|
||||
QLatin1String("__cpp_return_type_deduction"),
|
||||
QLatin1String("__cpp_rtti"),
|
||||
QLatin1String("__cpp_rvalue_references"),
|
||||
QLatin1String("__cpp_static_assert"),
|
||||
QLatin1String("__cpp_unicode_characters"),
|
||||
QLatin1String("__cpp_unicode_literals"),
|
||||
QLatin1String("__cpp_user_defined_literals"),
|
||||
QLatin1String("__cpp_variable_templates"),
|
||||
QLatin1String("__cpp_variadic_templates"),
|
||||
};
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::undefineCppLanguageFeatureMacrosForMsvc2015()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID
|
||||
&& m_projectPart.isMsvc2015Toolchain) {
|
||||
// Undefine the language feature macros that are pre-defined in clang-cl 3.8.0,
|
||||
// but not in MSVC2015's cl.exe.
|
||||
foreach (const QString ¯oName, languageFeatureMacros())
|
||||
m_options.append(QLatin1String("/U") + macroName);
|
||||
}
|
||||
}
|
||||
|
||||
QString CompilerOptionsBuilder::includeOption() const
|
||||
{
|
||||
return QLatin1String("-I");
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
virtual void addOptionsForLanguage(bool checkForBorlandExtensions = true);
|
||||
|
||||
void addMsvcCompatibilityVersion();
|
||||
void undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
protected:
|
||||
virtual bool excludeDefineLine(const QByteArray &defineLine) const;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace CppTools {
|
||||
|
||||
ProjectPart::ProjectPart()
|
||||
: project(0)
|
||||
, isMsvc2015Toolchain(false)
|
||||
, languageVersion(CXX14)
|
||||
, languageExtensions(NoExtensions)
|
||||
, qtVersion(UnknownQt)
|
||||
|
||||
@@ -104,6 +104,7 @@ public: // fields
|
||||
QByteArray projectDefines;
|
||||
QByteArray toolchainDefines;
|
||||
Core::Id toolchainType;
|
||||
bool isMsvc2015Toolchain;
|
||||
QString targetTriple;
|
||||
ProjectPartHeaderPaths headerPaths;
|
||||
QStringList precompiledHeaders;
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
#include "cppprojectfile.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
|
||||
#include <projectexplorer/abi.h>
|
||||
#include <projectexplorer/headerpath.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
@@ -279,6 +281,18 @@ QString targetTriple(ProjectExplorer::Project *project, const Core::Id &toolchai
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool projectHasMsvc2015Toolchain(ProjectExplorer::Project *project)
|
||||
{
|
||||
if (project) {
|
||||
if (ProjectExplorer::Target *target = project->activeTarget()) {
|
||||
if (ProjectExplorer::RunConfiguration *runConfig = target->activeRunConfiguration())
|
||||
return runConfig->abi().osFlavor() == ProjectExplorer::Abi::WindowsMsvc2015Flavor;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -341,6 +355,7 @@ void ProjectPartBuilder::evaluateProjectPartToolchain(
|
||||
|
||||
projectPart->toolchainDefines = toolChain->predefinedMacros(commandLineFlags);
|
||||
projectPart->toolchainType = toolChain->typeId();
|
||||
projectPart->isMsvc2015Toolchain = projectHasMsvc2015Toolchain(projectPart->project);
|
||||
projectPart->targetTriple = targetTriple(projectPart->project, toolChain->typeId());
|
||||
projectPart->updateLanguageFeatures();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user