summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2019-10-10 11:04:01 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2019-10-11 12:49:06 +0000
commit5165c037ebbc3948d777595610bc62beb275a9a8 (patch)
tree892f6116167c2887df571ad341c1371af2848ab4 /tests/unit
parent7a87dc0484bfe91ef7cba27e4b84993acd954beb (diff)
downloadqt-creator-5165c037ebbc3948d777595610bc62beb275a9a8.tar.gz
Clang: Avoid consuming gcc internal include paths
Given the (default) include paths of GCC, e.g. /usr/include/c++/7 /usr/include/x86_64-linux-gnu/c++/7 /usr/include/c++/7/backward /usr/lib/gcc/x86_64-linux-gnu/7/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed /usr/include/x86_64-linux-gnu /usr/include discard gcc-internal paths like /usr/lib/gcc/x86_64-linux-gnu/7/include as they are not relevant for clang and even confuse it with regard to #include_next. Paths below the gcc install dir are considered as gcc-internal. The install dir is queried with $ gcc -print-search-dirs Some GCC distributions, like MinGW, ship the standard library headers in the install dir. Ensure to not discard these. Fixes: QTCREATORBUG-22898 Change-Id: Ia85258fb01b72ad073e71390e003fe8268e3b01f Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unittest/headerpathfilter-test.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/unit/unittest/headerpathfilter-test.cpp b/tests/unit/unittest/headerpathfilter-test.cpp
index 79091e0a0b..dac2974ecf 100644
--- a/tests/unit/unittest/headerpathfilter-test.cpp
+++ b/tests/unit/unittest/headerpathfilter-test.cpp
@@ -27,6 +27,7 @@
#include <cpptools/headerpathfilter.h>
#include <projectexplorer/project.h>
+#include <projectexplorer/projectexplorerconstants.h>
namespace {
@@ -248,6 +249,51 @@ TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderLinux)
HasBuiltIn("/builtin_path")));
}
+// Include paths below the installation dir should be removed as they confuse clang.
+TEST_F(HeaderPathFilter, RemoveGccInternalPaths)
+{
+ projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7");
+ projectPart.toolchainType = ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID;
+ projectPart.headerPaths = {
+ HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/7/include", HeaderPathType::BuiltIn},
+ HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed", HeaderPathType::BuiltIn},
+ };
+ CppTools::HeaderPathFilter filter{projectPart,
+ CppTools::UseTweakedHeaderPaths::Yes,
+ "6.0",
+ CLANG_RESOURCE_DIR};
+
+ filter.process();
+
+ ASSERT_THAT(filter.builtInHeaderPaths, ElementsAre(HasBuiltIn(CLANG_RESOURCE_DIR)));
+}
+
+// MinGW ships the standard library headers in "<installdir>/include/c++".
+// Ensure that we do not remove include paths pointing there.
+TEST_F(HeaderPathFilter, RemoveGccInternalPathsExceptForStandardPaths)
+{
+ projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8(
+ "c:/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0");
+ projectPart.toolchainType = ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID;
+ projectPart.headerPaths = {
+ HeaderPath{"c:/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++", HeaderPathType::BuiltIn},
+ HeaderPath{"c:/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32", HeaderPathType::BuiltIn},
+ HeaderPath{"c:/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward", HeaderPathType::BuiltIn},
+ };
+
+ auto expected = projectPart.headerPaths;
+ expected << HeaderPath{CLANG_RESOURCE_DIR, HeaderPathType::BuiltIn};
+
+ CppTools::HeaderPathFilter filter{projectPart,
+ CppTools::UseTweakedHeaderPaths::Yes,
+ "6.0",
+ CLANG_RESOURCE_DIR};
+
+ filter.process();
+
+ ASSERT_THAT(filter.builtInHeaderPaths, ContainerEq(expected));
+}
+
TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderNoVersion)
{
projectPart.headerPaths = {