You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Support header shadowing diagnostics in Clang header search (llvm#162491)
When including a header file, multiple files with the same name may
exist across different search paths, like:
  |-- main.cpp
  |-- **header.h**
  |-- include
  |  └── **header.h**
The compiler usually picks the first match it finds (typically following
MSVC rules for current/include-chain paths first, then regular -I
paths), which may not be the user’s intended header.
This silent behavior can lead to subtle runtime API mismatches or
increase the cost of resolving errors such as “error: use of undeclared
identifier”, especially in large projects.
Therefore, this patch tries to provide a diagnostic message without
changing the current header selection. It does this by performing an
additional search for duplicate filenames across all search paths (both
MSVC rules and standard paths). This informs the user about a potential
"header shadowing" issue and clarifies which header path was actually
used.
Since header searching is much cheaper than file loading, the added
overhead should be within an acceptable range -- assuming the diagnostic
message is valuable.
"public framework header includes private framework header '%0'"
961
961
>, InGroup<FrameworkIncludePrivateFromPublic>;
962
+
def warn_header_shadowing : Warning<
963
+
"multiple candidates for header '%0' found; "
964
+
"directory '%1' chosen, ignoring others including '%2'">,
965
+
InGroup<ShadowHeader>, DefaultIgnore;
962
966
def warn_deprecated_module_dot_map : Warning<
963
967
"'%0' as a module map name is deprecated, rename it to %select{module.modulemap|module.private.modulemap}1%select{| in the 'Modules' directory of the framework}2">,
0 commit comments