forked from include-what-you-use/include-what-you-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix provision analysis with public headers
This fixes determination of types provided with type aliases and function declarations (fn return, "autocast") in the presence of mapping files. The problem was in that the `PublicHeaderIntendsToProvide` function considers as provided all the headers transitively included from a public header, despite they are may be themselves public and not have the explicit public-to-public mapping specified. It is convenient to avoid noisy suggestions of the library internals when handling instantiations of some external library templates, but may hinder expressing author intent when writing e.g. some own (user's) `typedef` (non-)providing a type from such a library. To achieve the more correct behavior, the logic from `OneUse::SetPublicHeaders()` function has been reused which takes into account only explicitly specified mappings. The drawback is that the use site vs. the decl site difference for default template arguments becomes worse (see `TestDefaultTplArgs()`). The use site handling still uses `PublicHeaderIntendsToProvide` (which is common way for template instantiation handling, as stated before). It may end up in that IWYU may suggest to remove an indirectly providing header from the template defining file (`-d1.h` from `-def_tpl_arg.h` in the test case) not suggesting to `#include` the default argument header at the use site because at the time of analysis `-d1.h` is present in `-def_tpl_arg.h` and "provides" all its directly and indirectly included stuff. OTOH, it may be fixed easily by means of including the appropriate header in the template instantiating file manually, and the IWYU behavior should become consistent. The main goal of these changes is to introduce `IsDirectlyIncluded` function which may be reused when fixing `UnresolvedLookupExpr`-related bugs (`PublicHeaderIntendsToProvide` doesn't work well in real-world cases for it).
- Loading branch information
1 parent
5e104d6
commit b2fdeaa
Showing
7 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,5 @@ struct AutocastInPartialSpec<T*> { | |
AutocastInPartialSpec(int) { | ||
} | ||
}; | ||
|
||
struct MappedToD1 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The primary reason to add this file is to mark "-d1.h" header as public. | ||
# Public headers have special handling in IWYU. | ||
[ | ||
{ "symbol": ["DirectStruct1", "private", "\"tests/cxx/iwyu_stricter_than_cpp-d1.h\"", "public"] }, | ||
{ "symbol": ["MappedToD1", "private", "\"tests/cxx/iwyu_stricter_than_cpp-d1.h\"", "public"] }, | ||
] |