Commit 08f0d37c authored by Nikolai Kosjar's avatar Nikolai Kosjar

ClangStaticAnalyzer: Undefine clang version macros for MSVC Kits

This fixes parsing of Qt 5.7.0 headers with a MSVC Kit.

Re-produce with:
  1) Open qt-essential-includes.pro or the *.qbs and configure it with a Qt
     5.7.0 MSVC2013 Kit.
  2) Run the analyzer.

Errors during analyzing occur in qtypetraits.h [1] because
 * Q_COMPILER_UNICODE_STRINGS is defined in qcompilerdetection.h because...
 * Q_CC_CLANG is defined because...
 * __clang* is defined.

Undefine the __clang* macros so the "right" compiler will be detected.

[1]
In file included from D:\dev\creator\creator-4.1\src\plugins\clangstaticanalyzer\unit-tests\qt-essential-includes\main.cpp:1:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include/QtCore\QtCore:4:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include/QtCore/qabstractanimation.h:43:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qobject.h:46:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qobjectdefs.h:48:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qnamespace.h:43:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qglobal.h:1139:
In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypeinfo.h:41:
D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypetraits.h(251,19) :  error: redefinition of 'QtPrivate::is_integral<unsigned short>'
template<> struct is_integral<char16_t> : true_type { };
                  ^~~~~~~~~~~~~~~~~~~~~
D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypetraits.h(235,19) :  note: previous definition is here
template<> struct is_integral<unsigned short> : true_type { };

Change-Id: I10da2a1daa6f5ea2828f7ea4bcf594050a585b61
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent 73f0ac37
......@@ -184,6 +184,7 @@ public:
optionsBuilder.addDefine("#define _X86INTRIN_H_INCLUDED\n");
optionsBuilder.addToolchainAndProjectDefines();
optionsBuilder.undefineClangVersionMacrosForMsvc();
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
optionsBuilder.addHeaderPathOptions();
optionsBuilder.addMsvcCompatibilityVersion();
......@@ -203,6 +204,23 @@ public:
{
}
public:
void undefineClangVersionMacrosForMsvc()
{
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
static QStringList macroNames {
"__clang__",
"__clang_major__",
"__clang_minor__",
"__clang_patchlevel__",
"__clang_version__"
};
foreach (const QString &macroName, macroNames)
add(QLatin1String("/U") + macroName);
}
}
private:
void addTargetTriple() override
{
......@@ -272,6 +290,14 @@ static QStringList createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(
return optionsBuilder.options();
}
static QStringList createOptionsToUndefineClangVersionMacrosForMsvc(const ProjectPart &projectPart)
{
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
optionsBuilder.undefineClangVersionMacrosForMsvc();
return optionsBuilder.options();
}
static QStringList tweakedArguments(const ProjectPart &projectPart,
const QString &filePath,
const QStringList &arguments,
......@@ -281,6 +307,7 @@ static QStringList tweakedArguments(const ProjectPart &projectPart,
prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple);
newArguments.append(createMsCompatibilityVersionOption(projectPart));
newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart));
newArguments.append(createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(projectPart));
return newArguments;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment