Tool to delete unneeded methods/enums, etc.

J

Julek

Hi,
is there a tool which parses cpp and h files, finds unused things, and
deletes them from code? For example unused methods, enums, enum
values, defines... It doesn't have to be sophisticated (it doesn't
have to check, that ClassA::funX is used somewhere, but ClassB::funX
is not used anywhere, so we can delete only ClassB::funX).

Thanks in advance!
 
J

Jerry Coffin

Hi,
is there a tool which parses cpp and h files, finds unused things, and
deletes them from code?

Yes. It's called an "optimizing compiler". :)
For example unused methods, enums, enum
values, defines... It doesn't have to be sophisticated (it doesn't
have to check, that ClassA::funX is used somewhere, but ClassB::funX
is not used anywhere, so we can delete only ClassB::funX).

Realistically, getting something like this to work correctly would be
quite difficult -- little short of a full-blown compiler could really do
the job correctly.
 
J

James Kanze

Yes. It's called an "optimizing compiler". :)
Realistically, getting something like this to work correctly would be
quite difficult -- little short of a full-blown compiler could really do
the job correctly.

FWIW: one Fortran compiler I used (around 1978) did output a
message when it suppressed a line because it couldn't be
reached, or otherwise did something which had no effect. This
could actually be very helpful---in one case, I remember getting
messages to the effect:
line x: removed, because variable YO is never used.
line y: variable Y0 used without being set.
I'm not sure about the relative utility of such a thing in C++,
however. The preprocessor makes it a bit awkward: what if I
don't use the enum E (defined in some header); maybe some other
code in another application does use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top