Comment #4 on issue 1249 by iven: iwyu removes some headers incorrectly
https://github.com/include-what-you-use/include-what-you-use/issues/1249
After I removed `--stdlib=libc++` from the command line, it works:
```bash
$ include-what-you-use main.cpp
(main.h has correct #includes/fwd-decls)
(main.cpp has correct #includes/fwd-decls)
```
I compared the logs, with `--stdlib=libc++`:
```
Adding a template-class type of interest: class IFontMgr -> class IFontMgr
main.cpp:5:11: (7 in tpl) [ TemplateName ] shared_ptr
main.cpp:5:11: (7 in tpl) [ TemplateArgument ] 0x56267a3a9698 <IFontMgr>
main.cpp:5:11: (8 in tpl, fwd decl) [ ElaboratedType ] 0x56267a3a9520 IFontMgr
main.cpp:5:11: (9 in tpl, fwd decl) [ RecordType ] 0x56267a3a9220 class IFontMgr
(Replaying full-use information from the cache for std::shared_ptr)
(For type std::shared_ptr<IFontMgr>):
Marked full-info use of decl 0x56267a003c50 std::shared_ptr (from /usr/lib/llvm-16/include/c++/v1/__memory/shared_ptr.h:459:59) at main.cpp:5:3
Comment:
main.cpp:5:11: (6) [ ImplicitCastExpr ] 0x56267a3cb468 ImplicitCastExpr 0x56267a3cb468 'element_type *(*)(void) const noexcept' <FunctionToPointerDecay>
`-DeclRefExpr 0x56267a3cb3e8 'element_type *(void) const noexcept' lvalue CXXMethod 0x56267a3be728 'operator->' 'element_type *(void) const noexcept'
main.cpp:5:11: (7) [ DeclRefExpr ] 0x56267a3cb3e8 DeclRefExpr 0x56267a3cb3e8 'element_type *(void) const noexcept' lvalue CXXMethod 0x56267a3be728 'operator->' 'element_type *(void) const noexcept'
Marked full-info use of decl 0x56267a01d008 std::shared_ptr::operator-> (from /usr/lib/llvm-16/include/c++/v1/__memory/shared_ptr.h:853:19) at main.cpp:5:11
Comment:
main.cpp:5:11: (7) [ FunctionCall ] 0x56267a3be728 element_type *operator->() const noexcept
Marked full-info use of decl 0x56267a01d008 std::shared_ptr::operator-> (from /usr/lib/llvm-16/include/c++/v1/__memory/shared_ptr.h:853:19) at main.cpp:5:11
Comment:
main.cpp:5:3: (6) [ MemberExpr ] 0x56267a3cb388 MemberExpr 0x56267a3cb388 'const std::shared_ptr<IFontMgr>':'const class std::shared_ptr<class IFontMgr>' lvalue ->fontMgr_ 0x56267a3c2c18
`-CXXThisExpr 0x56267a3cb348 'const class FontRenderer *' implicit this
```
without `--stdlib=libc++`:
```
User, not author, of typedef std::__shared_ptr_access<IFontMgr, __gnu_cxx::_S_atomic, false, false>::element_type owns the underlying type:
(For type class IFontMgr):
Marked full-info use of decl 0x555a179735c0 IFontMgr (from FontMgr.h:3:7) at main.cpp:5:13
Comment:
main.cpp:5:11: (5) [ CXXOperatorCallExpr ] 0x555a17982090 CXXOperatorCallExpr 0x555a17982090 'element_type *' '->'
|-ImplicitCastExpr 0x555a17982078 'element_type *(*)(void) const noexcept' <FunctionToPointerDecay>
| `-DeclRefExpr 0x555a17982000 'element_type *(void) const noexcept' lvalue CXXMethod 0x555a1791fca8 'operator->' 'element_type *(void) const noexcept'
`-ImplicitCastExpr 0x555a17981fd8 'const class std::__shared_ptr_access<class IFontMgr, __gnu_cxx::_S_atomic, false, false>' lvalue <UncheckedDerivedToBase (__shared_ptr -> __shared_ptr_access)>
`-MemberExpr 0x555a17981f78 'const std::shared_ptr<IFontMgr>':'const class std::shared_ptr<class IFontMgr>' lvalue ->fontMgr_ 0x555a179515d8
`-CXXThisExpr 0x555a17981f40 'const class FontRenderer *' implicit this
(For type class std::__shared_ptr_access<class IFontMgr, __gnu_cxx::_S_atomic, false, false>):
Marked full-info use of decl 0x555a178200a8 std::__shared_ptr_access (from /usr/include/c++/11/bits/shared_ptr_base.h:971:11) at main.cpp:5:3
Comment:
main.cpp:5:11: (6) [ ImplicitCastExpr ] 0x555a17982078 ImplicitCastExpr 0x555a17982078 'element_type *(*)(void) const noexcept' <FunctionToPointerDecay>
`-DeclRefExpr 0x555a17982000 'element_type *(void) const noexcept' lvalue CXXMethod 0x555a1791fca8 'operator->' 'element_type *(void) const noexcept'
main.cpp:5:11: (7) [ DeclRefExpr ] 0x555a17982000 DeclRefExpr 0x555a17982000 'element_type *(void) const noexcept' lvalue CXXMethod 0x555a1791fca8 'operator->' 'element_type *(void) const noexcept'
Marked full-info use of decl 0x555a17820828 std::__shared_ptr_access::operator-> (from /usr/include/c++/11/bits/shared_ptr_base.h:984:7) at main.cpp:5:11
Comment:
main.cpp:5:11: (7) [ FunctionCall ] 0x555a1791fca8 element_type *operator->() const noexcept
Marked full-info use of decl 0x555a17820828 std::__shared_ptr_access::operator-> (from /usr/include/c++/11/bits/shared_ptr_base.h:984:7) at main.cpp:5:11
Comment:
main.cpp:5:3: (6) [ ImplicitCastExpr ] 0x555a17981fd8 ImplicitCastExpr 0x555a17981fd8 'const class std::__shared_ptr_access<class IFontMgr, __gnu_cxx::_S_atomic, false, false>' lvalue <UncheckedDerivedToBase (__shared_ptr -> __shared_ptr_access)>
`-MemberExpr 0x555a17981f78 'const std::shared_ptr<IFontMgr>':'const class std::shared_ptr<class IFontMgr>' lvalue ->fontMgr_ 0x555a179515d8
`-CXXThisExpr 0x555a17981f40 'const class FontRenderer *' implicit this
Adding a template-class type of interest: class IFontMgr -> class IFontMgr
main.cpp:5:3: (8 in tpl) [ TemplateName ] shared_ptr
main.cpp:5:3: (8 in tpl) [ TemplateArgument ] 0x555a1791e098 <IFontMgr>
main.cpp:5:3: (9 in tpl, fwd decl) [ ElaboratedType ] 0x555a1791df20 IFontMgr
main.cpp:5:3: (10 in tpl, fwd decl) [ RecordType ] 0x555a1791dc00 class IFontMgr
(Replaying full-use information from the cache for std::shared_ptr)
(For type std::shared_ptr<IFontMgr>):
Marked full-info use of decl 0x555a1786c460 std::shared_ptr (from /usr/include/c++/11/bits/shared_ptr.h:122:11) at main.cpp:5:3
Comment:
main.cpp:5:3: (7) [ MemberExpr ] 0x555a17981f78 MemberExpr 0x555a17981f78 'const std::shared_ptr<IFontMgr>':'const class std::shared_ptr<class IFontMgr>' lvalue ->fontMgr_ 0x555a179515d8
`-CXXThisExpr 0x555a17981f40 'const class FontRenderer *' implicit this
```
When running without `--stdlib=libc++`, iwyu marks `IFontMgr` as full use because it thinks `shared_ptr<IFontMgr>` is typedef of `std::__shared_ptr_access<class IFontMgr, __gnu_cxx::_S_atomic, false, false>` in libstdc++?
https://github.com/include-what-you-use/include-what-you-use/blob/02b4e50687db8b245f9563c7530f851f9981252d/iwyu.cc#L1676