weixin_39822993 2020-11-30 11:25
浏览 0

choose parent #include file when conditionally incuding

Originally reported on Google Code with ID 56


Say, file sys/cdefs.h contains:

#ifdef __ELF__
#include <sys>
#else
#include <sys>
#endif

iwyu suggests removing the #include for sys/cdefs.h and adding an #include <sys>

If the #include is conditional, iwyu should use the top-most ancestor include file
that is unconditional.
</sys></sys></sys>

Reported by MarkoSchuetz on 2011-07-23 15:17:17

该提问来源于开源项目:include-what-you-use/include-what-you-use

  • 写回答

8条回答 默认 最新

  • weixin_39822993 2020-11-30 11:25
    关注
    
    It's an interesting idea!  I've tried to come up with an example where this isn't a
    good idea, but it's hard for me to.  That's not to say there aren't any; I just don't
    have a feel for how often it occurs.
    
    My basic philosophy for system includes is to not try to come up with rules, but to
    just hard-code knowledge in iwyu_include_picker.cc.  It would certainly be easy to
    add a mapping from cdefs_*.h to cdefs.h, which is how I would try to solve this immediate
    problem.  But I wonder if your idea is a good one to try to generalize things.  Feel
    free to draw up a patch that implements it if you like, and we can play around with
    it.
    

    Reported by csilvers on 2011-07-25 21:06:35

    评论

报告相同问题?