Bug 146619 - Remove unused #includes from C/C++ files
Summary: Remove unused #includes from C/C++ files
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://wiki.documentfoundation.org/D...
Whiteboard:
Keywords: difficultyMedium, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2022-01-06 15:00 UTC by Hossein
Modified: 2022-04-28 09:05 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2022-01-06 15:00:02 UTC
While the source code is changed constantly, there are situations that some unused include remain in the C/C++ files.

In order to speed up the compilation, it is good to remove such includes. Finding those superfluous #includes is not straightforward, but there are many tricks and tools to do that. For example, please see these question and answers:

Detecting superfluous #includes in C/C++?
https://stackoverflow.com/questions/614794

How should I detect unnecessary #include files in a large C++ project?
https://stackoverflow.com/questions/74326

For this EasyHack, you should find such instances, remove them and after that LibreOffice source code should compile successfully, and all the tests should pass.
Comment 1 Stephan Bergmann 2022-01-06 15:23:24 UTC
(note that, by convention,

  #include <sal/config.h>

should be at the top of every C/C++ source and include file across the code base)
Comment 2 Aron Budea 2022-02-12 05:12:55 UTC
Noting for reference, Gabor did such work for bug 42949 in the past using Include What You Use.
Comment 3 Gabor Kelemen (allotropia) 2022-02-13 13:10:29 UTC
(In reply to Aron Budea from comment #2)
> Noting for reference, Gabor did such work for bug 42949 in the past using
> Include What You Use.

I'm still doing it :)

The LibreOffice-ish way to do this is by using bin/find-unneeded-includes for which I'm planning to write a howto + tips & tricks page to the wiki, to make it really beginner friendly.
Comment 4 Gabor Kelemen (allotropia) 2022-04-28 08:55:13 UTC
Added the initial wiki page, please review and ask on the discussion page if something is not obvious.
Other than that, newcomers can now start to do this sort of cleanup work.