4 ms·
Personally I don't like this. Often enough there's includes in headers, which are an implementation detail for the functionality in the originally included head
by anarazel 11y ago
Personally I don't like this. Often enough there's includes in headers, which are an implementation detail for the functionality in the originally included header. Iwyu will just include that, increasing coupling between components.
- deleted 11y ago[deleted]
- bnegreve 11y agoI don't get it, can you give an example?
- revelation 11y agoBig libraries like Boost and OpenCV usually have meta-headers for features and components that just include all the other headers for that particular part you want to use. (e.g. https://github.com/Itseez/opencv/blob/master/include/opencv2/opencv.hpp https://github.com/Itseez/opencv/blob/master/include/opencv2...) A tool like this would see right through that and walk the tree all the way to the final leaf headers that actually implement the parts you use. This not only means one single include will balloon to many smaller ones, but when the library moves things around internally your code will break. (Unclear if this is what this tool in particular will do, but I've certainly seen this behavior with Clion for example when it recommends what header to include.)
- maxlybbert 11y agoThe obvious one would be #include <windows.h>. I have never checked to see how big that file actually is, but it's not anywhere near what you would think based on what functions MSDN says need you to #include it for. The truth is, it #includes several other files, because Microsoft, in its infinite wisdom decided that, for the most part, programmers don't have to know what file a declaration is actually in, they just need to remember #include <windows.h>.
- epistasis 11y agoI don't think the program does that, if I understand your post. A more accurate name might b "exclude what you don't use." It doesn't add in chained includes, it just lets you know about superfluous includes.
- anarazel 11y agoI was pretty sure it does that, since people in projects I work on use it. To make sure that I'm correct, I just ran it on some code I work on, and indeed, it wants to add (...c should add these lines ... ) implementation details to a lot of sourcefiles.
- throwawayaway 11y agoI guess this can be a problem for cross platform code, yes?
- DrJokepu 11y agoOr even compatability with different versions of the same compiler, runtime or libraries.
- cheez 11y agoLooks like you can use flags on the fix_includes.py script to avoid that, so something like: fix_includes.py --ignore_re '^boost' < /tmp/out
- jlebar 11y agoYou can use the IWYU "export" pragma to inform IWYU that this is what you're doing. https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md#iwyu-pragma-export https://github.com/include-what-you-use/include-what-you-use...
- anarazel 11y agoNot a particularly good solution imo, because that means modifying random libraries I use. Besides adding verbiage. I can see value in removing unneeded includes, and doing that supervised every once in a while. The way it wants to add includes? Not so much.