diff --git a/src/plugins/cpptools/headerpathfilter.cpp b/src/plugins/cpptools/headerpathfilter.cpp index b656f8e136e..c7265e40444 100644 --- a/src/plugins/cpptools/headerpathfilter.cpp +++ b/src/plugins/cpptools/headerpathfilter.cpp @@ -71,15 +71,10 @@ void HeaderPathFilter::removeGccInternalIncludePaths() return; const Utils::FilePath gccInstallDir = projectPart.toolChainInstallDir; - auto isGccInternalInclude = [gccInstallDir](const HeaderPath &headerPath){ - const auto includePath = Utils::FilePath::fromString(headerPath.path); - if (includePath.isChildOf(gccInstallDir)) { - const QString remainingPath = headerPath.path.mid(gccInstallDir.toString().size()); - // MinGW ships the standard library headers in "/include/c++". - // Ensure that we do not remove include paths pointing there. - return !remainingPath.startsWith("/include/c++"); - } - return false; + auto isGccInternalInclude = [gccInstallDir](const HeaderPath &headerPath) { + const auto filePath = Utils::FilePath::fromString(headerPath.path); + return filePath == gccInstallDir.pathAppended("include") + || filePath == gccInstallDir.pathAppended("include-fixed"); }; Utils::erase(builtInHeaderPaths, isGccInternalInclude); diff --git a/tests/unit/unittest/headerpathfilter-test.cpp b/tests/unit/unittest/headerpathfilter-test.cpp index da9d735f49d..b5589e8ec35 100644 --- a/tests/unit/unittest/headerpathfilter-test.cpp +++ b/tests/unit/unittest/headerpathfilter-test.cpp @@ -245,7 +245,8 @@ TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderLinux) HasBuiltIn("/builtin_path"))); } -// Include paths below the installation dir should be removed as they confuse clang. +// GCC-internal include paths like /include and might confuse +// clang and should be filtered out. clang on the command line filters them out, too. TEST_F(HeaderPathFilter, RemoveGccInternalPaths) { projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7"); @@ -264,7 +265,8 @@ TEST_F(HeaderPathFilter, RemoveGccInternalPaths) ASSERT_THAT(filter.builtInHeaderPaths, ElementsAre(HasBuiltIn(CLANG_RESOURCE_DIR))); } -// MinGW ships the standard library headers in "/include/c++". +// Some distributions ship the standard library headers in "/include/c++" (MinGW) +// or e.g. "/include/g++-v8" (Gentoo). // Ensure that we do not remove include paths pointing there. TEST_F(HeaderPathFilter, RemoveGccInternalPathsExceptForStandardPaths) {