[cfe-dev] Finding redundant #includes
snaroff at apple.com
Sat Dec 12 12:26:28 PST 2009
Good points. I think the diagnostics would need some interpretation
(by a human).
If we wanted to get "fancy", we could devise some way to determine if
a declaration occurred within a #ifdef clause (special casing the
#ifndef that is commonly at the begin/end of every C header).
Unfortunately, any feature involving the preprocessor is usually more
complex than it should be (given the ability to arbitrary mutate
headers in different contexts...including the same compilation unit:-(
Fortunately, ObjC headers and user-defined (i.e. non-system) headers
usually aren't as gross...
On Dec 12, 2009, at 2:56 PM, Ted Kremenek wrote:
> Doing it correctly wouldn't be too hard from the AST perspective,
> but would be tricky when considering preprocessor logic. Any macros
> defined in a header and later used outside that header causes a
> dependency. Moreover, if a file can be compiled under different
> contexts, e.g., on Mac OS X one can compile for i386, x86_64, etc.,
> then the "liveness" of a #include can change between translations.
> On Dec 12, 2009, at 8:51 AM, steve naroff wrote:
>> Hi Andrew,
>> I don't believe we currently have such a feature (though it's an
>> interesting idea).
>> Implementing this wouldn't be too difficult, however it certainly
>> isn't a "quick hack".
>> On Dec 12, 2009, at 11:13 AM, Andrew Price wrote:
>>> Can clang's analysis features help me find #includes which are no
>>> required in a C source file? I'm working on cleaning up some old
>>> code and it would be good to have this functionality.
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
More information about the cfe-dev