Live data from Hacker News

Include-what-you-use: Clang tool to analyze includes in C and C++ source files

include-what-you-use.org

21–30 of 43 posts

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#21
post #5

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.

Looks like you can use flags on the fix_includes.py script to avoid that, so something like:

    fix_includes.py --ignore_re '^boost' 

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#22

Earlier quoted context omitted.

I 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.

I 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.

I guess this can be a problem for cross platform code, yes?

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#23
post #10

I'm trying to get into refactoring (and even semantic analysis, and code-generation) for large C++ codebases using libclang, libtool, and the ilk. Any guides to get started, and/or best practices? Does it increase productivity by order of magnitude? (I'd like to think so. I think it's madness not to use any AST tool when working on large codebases). Also I'm assuming "white-box" C/C++ tools like libclang/libtooling a…

I think you'll enjoy this talk: CppCon 2015: Atila Neves "Emacs as a C++ IDE" - https://m.youtube.com/watch?v=5FQwQ0QWBTU

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#24

Earlier quoted context omitted.

I 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.

I guess this can be a problem for cross platform code, yes?

Or even compatability with different versions of the same compiler, runtime or libraries.

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#25
post #23
post #10

I'm trying to get into refactoring (and even semantic analysis, and code-generation) for large C++ codebases using libclang, libtool, and the ilk. Any guides to get started, and/or best practices? Does it increase productivity by order of magnitude? (I'd like to think so. I think it's madness not to use any AST tool when working on large codebases). Also I'm assuming "white-box" C/C++ tools like libclang/libtooling a…

I think you'll enjoy this talk: CppCon 2015: Atila Neves "Emacs as a C++ IDE" - https://m.youtube.com/watch?v=5FQwQ0QWBTU

Great talk.

So he created cmake-ide for emacs. I'm wondering is there an equivalent for make projects.

EDIT 1: The github page [1] says "It automatically detects Ninja and Make builds and sets the compile command accordingly". I'm wondering if that means make is fully supported.

[1] https://github.com/atilaneves/cmake-ide

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#26
post #5

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.

You 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...

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#27
This seems like an awesome tool. I was thinking about going trough a code base for an hobby project a while ago. But this tool could make it a much easier task. I haven't tried following the instructions yet. But it seems to be correct. Good work!

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#28
post #26
post #5

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.

You 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...

Not 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.

Re: Include-what-you-use: Clang tool to analyze includes in C and C++ source files

#30
How about a tool to "exclude what you don't use"?

I have several personal hacks for doing this I have written over the years but I've yet to find anyone else who tried to automate it.

For example, one task is to determine the functions in a library that are not actually used in your program and exclude those from linking, instead of blindly linking libraries full of unused functions (that sometimes cause name conflicts).

Post reply on HN