Clang: Fix removing gcc internal include paths

Amends 5165c037eb.

Gentoo has the standard library headers installed in e.g.
<installdir>/include/g++-v8 and we excluded those. MinGW with the
standard library headers in <installdir>/include/c++ was whitelisted.

Instead of whitelistening more dirs that could contain standard library
headers, regard

  <installdir>/include
  <installdir>/include-fixed

as gcc internal include paths to remove. These seem to be stable across
distributions.

Task-number: QTCREATORBUG-23330
Change-Id: I44965d2030b4ea5a9dd269400faf19c3df89f5a6
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Nikolai Kosjar
2019-12-19 10:56:20 +01:00
parent 32018623a4
commit 4fdd944617
2 changed files with 8 additions and 11 deletions

View File

@@ -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 "<installdir>/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);

View File

@@ -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 <installdir>/include and <installdir/include-next> 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 "<installdir>/include/c++".
// Some distributions ship the standard library headers in "<installdir>/include/c++" (MinGW)
// or e.g. "<installdir>/include/g++-v8" (Gentoo).
// Ensure that we do not remove include paths pointing there.
TEST_F(HeaderPathFilter, RemoveGccInternalPathsExceptForStandardPaths)
{