Comment #4 on issue 945 by kimgr: IWYU suggests forward declaration for unordered_map's mapped_type (with libstdc++)
https://github.com/include-what-you-use/include-what-you-use/issues/945
I still think there's some disconnect between how IWYU works, and what you're describing.
IWYU does not permute the `#include` list until the program compiles with the minimal set. Rather, it looks at all uses in the main file of a compilation unit, and tries to attribute them to the right declaration location (whether inside itself, its associated header (`foo.h` for `foo.cpp`) or a header file in its transitive `#include` closure).
Note that it also pulls some tricks with templates to look at all uses in a template definition vs all uses in a template _instantiation_, and attribute them to the right place.
And it tries to understand what's a full use vs forward-declare use, something that's surprisingly non-obvious.
Once all uses and their corresponding declaration location are collected, they're run through a so-called mapping, to resolve things like `<bits/vector.tcc> => <vector>` or `std::string => <string>`.
Finally the mapped desired headers and forward-declarations are compared to the main file's actual headers/fwd-decls, and the difference is reported.
(note: I don't think it's exactly this clear-cut, but it really should be :))
So when `Foo` is mentioned as a forward-declaration with one standard library implementation and a full use with another, that indicates that IWYU's template instantiation logic or full vs fwd-decl analysis has made a wrong turn somewhere. Remember, from IWYU's point-of-view, `unordered_map` is just C++ code, it doesn't know it's part of the standard library until mapping-time, if ever.
That's why I'm curious about comparative logs from the two cases, to see how the ASTs are different, and how IWYU's analysis differs between the two.
And that's why I don't really see how to "disable unsafe transformations" -- IWYU doesn't really have a notion of safety, it assumes its analysis is 100% correct and lets it play out. And I'm not sure how to phrase any hints to it in this scenario...
As for short-term wins, `// IWYU pragma: keep` is probably your best bet.