Skip to content

Commit cde15fa

Browse files
committed
Suppress check for system headers
1 parent b0d265d commit cde15fa

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ void HeaderSearch::DiagnoseHeaderShadowing(
921921
It = FromDir;
922922
}
923923
for (; It != search_dir_end(); ++It) {
924+
// Suppress check for system headers, as duplicates are often intentional.
925+
if (It->getDirCharacteristic() != SrcMgr::C_User)
926+
continue;
924927
SmallString<1024> TmpPath = It->getName();
925928
llvm::sys::path::append(TmpPath, Filename);
926929
if (auto File = getFileMgr().getFileRef(TmpPath, false, false)) {

clang/test/Preprocessor/header-shadowing.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
// SHADOWING: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}include1' chosen, ignoring '{{.*}}include2' and others [-Wshadow-header]
1212
// SHADOWING: warning: include1/header.h included!
13-
// SHADOWING: warning: include2/header.h included!
14-
// SHADOWING: warning: system1/stdio.h included!
1513
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}include2' chosen, ignoring '{{.*}}include1' and others [-Wshadow-header]
14+
// SHADOWING: warning: include2/header.h included!
1615
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'stdio.h' found; directory '{{.*}}system1' chosen, ignoring '{{.*}}system2' and others [-Wshadow-header]
16+
// SHADOWING: warning: system1/stdio.h included!
1717

1818
/// Check that the diagnostic is only performed once in MSVC compatibility mode.
1919
// RUN: %clang_cc1 -fms-compatibility -Wshadow-header -Eonly %t/t.c -I %t -I %t/foo -I %t/foo/bar 2>&1 | FileCheck %s --check-prefix=SHADOWING-MS

0 commit comments

Comments
 (0)