As the title says... is anyone aware of a tool (ideally, as part of Qt Creator) to remove unused header files in a CPP file?
Cheers, Alan.
As the title says... is anyone aware of a tool (ideally, as part of Qt Creator) to remove unused header files in a CPP file?
Cheers, Alan.
There is no such tool. I don't see how you'd like to detect if a header file is "used" or not.
You can have relationships between header files such as those:
Qt Code:
/* b.h */ #ifndef A #define A 8 #endifTo copy to clipboard, switch view to plain text mode
and then you have:
So which ones are "used" and which are not?Qt Code:
#include "a.h" #include "b.h"To copy to clipboard, switch view to plain text mode
I would call what you gave as an example as very bad programming, but maybe that's just me?...
I assure you that you daily use a lot of headers such as these.
Sadly, I wouldn't be at all surprised if you were right and, in that context, I appreciate your original comment.
Otherwise, someone pointed me to https://code.google.com/p/include-what-you-use/. I wonder how that (beta) tool would handle your example...
No idea. However no tool will be able to detect that both files are needed as when a.h is present then b.h is not needed but once you remove a.h (or better yet have an ifndef there as well) b.h (or equivalent) is required despite the fact it is not used originally. It becomes even more complex with:
Qt Code:
#ifdef Q_OS_UNIX #include "a.h" #endif #include "b.h"To copy to clipboard, switch view to plain text mode
I'm sure I can find myrriads of other examples when such automatic cleanup would fail. Sorry but no tool can replace the process of thinking about what one's doing.
Bookmarks