简体   繁体   中英

C++ unused headers

I would like to remove some unused headers from the large codebase. I know that there are some open-source tools but number of false positives is too big. The idea was to run script for each file. Consequently, remove include, tries to compile, if compile goes to next line (with include removed), otherwise leave include and go to the next line.

Is there any problems connected with this idea, looking in the long-term? Or is there any easier option to try?

Is there any problems connected with this idea

Yes. A file can compile successfully even if it has missing include files, so this can have false positives, and may remove headers that are actually used.

It is quite a difficult task to analyse which headers should be included, and which are unnecessary, both manually and automatically. Tools have been made to do the checking automatically. Even if "number of false positives is too big ", it's still (in my experience) a small fraction of all included headers, so it is far less work to check results of such tool than compare includes of every file to the entire content of those files. Even the script that you suggest can be better than nothing, as long as you don't remove the includes without manual checking.

It helps manual checking to make the files as small as possible. As a side-effect, this also makes incremental compilation much faster (but compilation form scratch slower).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM