aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-07-09 09:44:39 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-07-09 17:24:16 +0000
commit782ca5d8d8e88b25b3424848c1297caf94a66585 (patch)
tree7009c9e973e870f6d1c362c65c19f4e05a332829
parentd964e91432b543c66790172757a1616214b3f0fd (diff)
Clang: Fix error when including float.h with mingw
Prevent mingw from trying to #include_next a private header from a path we cannot add to our list of includes. Fixes: QTCREATORBUG-24251 Task-number: QTCREATORBUG-24027 Change-Id: I18a9db130b9c2265cd208c3506d08d2e1c4cee45 Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--share/qtcreator/cplusplus/wrappedMingwHeaders/float.h34
-rw-r--r--src/plugins/cpptools/compileroptionsbuilder.cpp49
-rw-r--r--src/plugins/cpptools/compileroptionsbuilder.h5
-rw-r--r--tests/unit/unittest/compileroptionsbuilder-test.cpp33
4 files changed, 104 insertions, 17 deletions
diff --git a/share/qtcreator/cplusplus/wrappedMingwHeaders/float.h b/share/qtcreator/cplusplus/wrappedMingwHeaders/float.h
new file mode 100644
index 0000000000..8edb202a80
--- /dev/null
+++ b/share/qtcreator/cplusplus/wrappedMingwHeaders/float.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+// MinGW's "public" float.h includes a "private" float.h via #include_next.
+// We don't have access to the private header, because we cannot add its directory to
+// the list of include paths due to other headers in there that confuse clang.
+// Therefore, we prevent inclusion of the private header by setting a magic macro.
+// See also QTCREATORBUG-24251.
+#ifdef __MINGW32__ // Redundant, but let's play it safe.
+#define __FLOAT_H
+#include_next <float.h>
+#endif
diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp
index 1e9568294a..a4aaa0bd32 100644
--- a/src/plugins/cpptools/compileroptionsbuilder.cpp
+++ b/src/plugins/cpptools/compileroptionsbuilder.cpp
@@ -155,6 +155,7 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind,
addExtraOptions();
insertWrappedQtHeaders();
+ insertWrappedMingwHeaders();
return options();
}
@@ -285,6 +286,16 @@ void CompilerOptionsBuilder::enableExceptions()
add("-fexceptions");
}
+void CompilerOptionsBuilder::insertWrappedQtHeaders()
+{
+ insertWrappedHeaders(wrappedQtHeadersIncludePath());
+}
+
+void CompilerOptionsBuilder::insertWrappedMingwHeaders()
+{
+ insertWrappedHeaders(wrappedMingwHeadersIncludePath());
+}
+
static QString creatorResourcePath()
{
#ifndef UNIT_TESTS
@@ -294,19 +305,26 @@ static QString creatorResourcePath()
#endif
}
-void CompilerOptionsBuilder::insertWrappedQtHeaders()
+void CompilerOptionsBuilder::insertWrappedHeaders(const QStringList &relPaths)
{
if (m_useTweakedHeaderPaths == UseTweakedHeaderPaths::No)
return;
+ if (relPaths.isEmpty())
+ return;
- QStringList wrappedQtHeaders;
- addWrappedQtHeadersIncludePath(wrappedQtHeaders);
+ QStringList args;
+ for (const QString &relPath : relPaths) {
+ static const QString baseDir = creatorResourcePath() + "/cplusplus";
+ const QString fullPath = baseDir + '/' + relPath;
+ QTC_ASSERT(QDir(fullPath).exists(), continue);
+ args << includeUserPathOption << QDir::toNativeSeparators(fullPath);
+ }
const int index = m_options.indexOf(QRegularExpression("\\A-I.*\\z"));
if (index < 0)
- add(wrappedQtHeaders);
+ add(args);
else
- m_options = m_options.mid(0, index) + wrappedQtHeaders + m_options.mid(index);
+ m_options = m_options.mid(0, index) + args + m_options.mid(index);
}
void CompilerOptionsBuilder::addHeaderPathOptions()
@@ -686,19 +704,18 @@ bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro
return false;
}
-void CompilerOptionsBuilder::addWrappedQtHeadersIncludePath(QStringList &list) const
+QStringList CompilerOptionsBuilder::wrappedQtHeadersIncludePath() const
{
- static const QString resourcePath = creatorResourcePath();
- static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders";
- QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;);
+ if (m_projectPart.qtVersion == Utils::QtVersion::None)
+ return {};
+ return {"wrappedQtHeaders", "wrappedQtHeaders/QtCore"};
+}
- if (m_projectPart.qtVersion != Utils::QtVersion::None) {
- const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
- list.append({includeUserPathOption,
- QDir::toNativeSeparators(wrappedQtHeadersPath),
- includeUserPathOption,
- QDir::toNativeSeparators(wrappedQtCoreHeaderPath)});
- }
+QStringList CompilerOptionsBuilder::wrappedMingwHeadersIncludePath() const
+{
+ if (m_projectPart.toolchainType != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID)
+ return {};
+ return {"wrappedMingwHeaders"};
}
void CompilerOptionsBuilder::addProjectConfigFileInclude()
diff --git a/src/plugins/cpptools/compileroptionsbuilder.h b/src/plugins/cpptools/compileroptionsbuilder.h
index b2c8313771..ee7e373312 100644
--- a/src/plugins/cpptools/compileroptionsbuilder.h
+++ b/src/plugins/cpptools/compileroptionsbuilder.h
@@ -71,6 +71,7 @@ public:
void addCompilerFlags();
void enableExceptions();
void insertWrappedQtHeaders();
+ void insertWrappedMingwHeaders();
void addLanguageVersionAndExtensions();
void updateFileLanguage(ProjectFile::Kind fileKind);
@@ -97,7 +98,9 @@ public:
private:
void addIncludeDirOptionForPath(const ProjectExplorer::HeaderPath &path);
bool excludeDefineDirective(const ProjectExplorer::Macro &macro) const;
- void addWrappedQtHeadersIncludePath(QStringList &list) const;
+ void insertWrappedHeaders(const QStringList &paths);
+ QStringList wrappedQtHeadersIncludePath() const;
+ QStringList wrappedMingwHeadersIncludePath() const;
QByteArray msvcVersion() const;
private:
diff --git a/tests/unit/unittest/compileroptionsbuilder-test.cpp b/tests/unit/unittest/compileroptionsbuilder-test.cpp
index 2a6bfd8462..76fe2be066 100644
--- a/tests/unit/unittest/compileroptionsbuilder-test.cpp
+++ b/tests/unit/unittest/compileroptionsbuilder-test.cpp
@@ -475,6 +475,39 @@ TEST_F(CompilerOptionsBuilder, InsertWrappedQtHeaders)
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(IsPartOfHeader("wrappedQtHeaders")));
}
+TEST_F(CompilerOptionsBuilder, InsertWrappedMingwHeadersWithNonMingwToolchain)
+{
+ CppTools::CompilerOptionsBuilder builder{
+ projectPart,
+ CppTools::UseSystemHeader::Yes,
+ CppTools::UseTweakedHeaderPaths::Yes,
+ CppTools::UseLanguageDefines::No,
+ CppTools::UseBuildSystemWarnings::No,
+ "dummy_version",
+ ""};
+
+ builder.insertWrappedMingwHeaders();
+
+ ASSERT_THAT(builder.options(), Not(Contains(IsPartOfHeader("wrappedMingwHeaders"))));
+}
+
+TEST_F(CompilerOptionsBuilder, InsertWrappedMingwHeadersWithMingwToolchain)
+{
+ CppTools::CompilerOptionsBuilder builder{
+ projectPart,
+ CppTools::UseSystemHeader::Yes,
+ CppTools::UseTweakedHeaderPaths::Yes,
+ CppTools::UseLanguageDefines::No,
+ CppTools::UseBuildSystemWarnings::No,
+ "dummy_version",
+ ""};
+ projectPart.toolchainType = ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID;
+
+ builder.insertWrappedMingwHeaders();
+
+ ASSERT_THAT(builder.options(), Contains(IsPartOfHeader("wrappedMingwHeaders")));
+}
+
TEST_F(CompilerOptionsBuilder, SetLanguageVersion)
{
compilerOptionsBuilder.updateFileLanguage(ProjectFile::CXXSource);