Clang-tidy eliminate unused parts of headers

Hey there,

I have a simple question. Let’s say we include an header that defines two structs, but we only use one of them, so half of the included header is not actually used.

Is there such a mechanism in Clang/Clang-tidy to detect this? It could even be at preprocessing time…

I hope my question is clear, looking forward to seeing your answer!

eliminate them in what sense? Remove them from the AST? (by the time you know this, you’ve built the whole AST anyway, so maybe there’s not much to be gained by going back and removing things?)

But no, generally the AST isn’t editable like that - it doesn’t keep use lists, etc, and the memory management isn’t setup to deallocate parts of the AST.

There is/will be an include cleaner that tells you which includes you don’t need: