fix: make autoware_cmake Clang-friendly #11
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, many packages in Autoware cannot be built with Clang (for the purposes of this PR, Clang = Clang-15, the newest version packaged on Ubuntu 22.04).
This PR demotes a number of additional compiler warnings only output by Clang from error to warning, in order to make a large number of Autoware packages buildable while staying minimally invasive. The main aim of this PR is to facilitate a timely introduction of Clang-Tidy across all Autoware packages.
Why Clang?
Clang provides the foundation for most modern state-of-the-art static analysis tools, such as Clang-Tidy and FB-Infer. Static analysis is of utmost importance to catch bugs before they hit production, especially in autonomous driving. Not having Clang support prevents us from fully introducing this common industry practice. Also see the Clang-Tidy discussion.
Further, Clang detects many more problems in the source code, thus giving developers better input on how to improve their code. Clang-specific features might also be a reason for some developers, see this discussion.
The current situation
Currently, out of 347 packages, 17 (5%) fail on Clang due to compiler errors, preventing 172 (50%) dependent packages from being built. Note that even with fixes in those 17 packages, other packages do have compiler errors as well.
Root cause
As Clang detects more code problems than GCC, and since
-Werror
is set for both compilers, the additional warnings flagged by Clang are promoted to error and cause many packages' builds to fail.These errors (taken from the fixed log retroactively) are preventing Autoware from being built*:
Detailed warnings here:
warnings.txt
Full log (before):
build-old.log
Full log (after):
build-new.log
Possible fixes
The first option is best handled by architects or teams such as the Autoware engineering team, as this is a coordinated effort involving many contributors.
This PR implements the second option, and since all these warnings are in addition to warnings similar to GCC's ones, I think it is fine to not treat them as error temporarily. Build quality will still not be lower than that produced by GCC.
Effects of this PR
Out of 347 packages, 3 (<1%) fail on Clang, preventing 6 (2%) dependent packages from being built.
This is an 👉 👉 improvement of 114% 👈 👈 in the number of successfully buildable packages!
To get a list of all warnings that were promoted to error and caused a build failure, run:
*: Build command:
Tests performed
Not applicable.
Effects on system behavior
Pre-review checklist for the PR author
The PR author must check the checkboxes below when creating the PR.
In-review checklist for the PR reviewers
The PR reviewers must check the checkboxes below before approval.
Post-review checklist for the PR author
The PR author must check the checkboxes below before merging.
After all checkboxes are checked, anyone who has write access can merge the PR.