Clang-Tidy Guidelines#
Weekly Clang-Tidy analysis report for main
branch is here (updated every Sunday).
Information: Due to the lack of the header files of CUDA or NVML, Perception modules and NVML GPU Monitor can not be analyzed correctly by clang-tidy-pr in autoware.iv repository. You may find some clang-errors and false positives.
This document follows the convention of RFC2119.
How to use Clang-Tidy on your local machine#
First, install Clang-Tidy.
# Ubuntu/Debian
sudo apt install clang-tidy
Next, build your package with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
option.
cd ~/autoware.proj
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Finally, run ./scripts/clang-tidy-package.sh
.
./scripts/clang-tidy-package.sh <path-to-your-package>
For example:
./scripts/clang-tidy-package.sh src/autoware/autoware.iv/common/util/autoware_utils/
Or, execute Clang-Tidy directly.
clang-tidy -p build/compile_commands.json <your-source-code>
Severity Level#
The severity level of check rules are defined by CodeChecker, not by Clang-Tidy itself. The level definitions of rules can be found here.
High#
We MUST fix the code problems pointed out by Clang-Tidy.
Middle#
We SHOULD fix the code problems pointed out by Clang-Tidy.
Low#
We MAY fix the code problems pointed out by Clang-Tidy. But some rules SHOULD NOT be ignored. See Rules section.
Style#
We MAY fix the code problems pointed out by Clang-Tidy. But some rules SHOULD NOT be ignored. See Rules section.
Rules#
Some rules are disabled by default to prevent false-positives that are annoying.
clang-diagnostic-*
#
We MUST fix the code problems detected by clang-diagnostic-* rules.
These rules come from Clang++ compile-time errors and warnings.
boost-*
#
We MUST fix the code problems detected by boost-_ rules if these are not false-positives.
boost-use-to-string [LOW] (doc)#
bugprone-*
#
We SHOULD fix the code problems detected by bugprone-* rules if these are not false-positives.
bugprone-argument-comment [LOW] (doc)#
bugprone-assert-side-effect [MEDIUM] (doc)#
bugprone-bad-signal-to-kill-thread [MEDIUM] (doc)#
bugprone-bool-pointer-implicit-conversion [LOW] (doc)#
bugprone-branch-clone [LOW] (doc)#
Sometimes the clones are intentional as follows. We MAY ignore safely. (Note that the following code violates the modernize-make-unique rule)
} else if (type == autoware_perception_msgs::msg::Semantic::MOTORBIKE) {
model_ptr.reset(new normal::BoundingBoxModel);
} else if (type == autoware_perception_msgs::msg::Semantic::BICYCLE) {
model_ptr.reset(new normal::BoundingBoxModel);
}
bugprone-copy-constructor-init [MEDIUM] (doc)#
bugprone-dangling-handle [HIGH] (doc)#
bugprone-dynamic-static-initializers [MEDIUM] (doc)#
bugprone-exception-escape [MEDIUM] (doc)#
bugprone-fold-init-type [HIGH] (doc)#
bugprone-forward-declaration-namespace [LOW] (doc)#
bugprone-forwarding-reference-overload [LOW] (doc)#
bugprone-inaccurate-erase [HIGH] (doc)#
bugprone-incorrect-roundings [HIGH] (doc)#
(bugprone-infinite-loop) [MEDIUM] (doc)#
Disabled because the rule falls into the infinite-loop when checking some ROS functions, such as spin()
.
bugprone-integer-division [MEDIUM] (doc)#
bugprone-lambda-function-name [LOW] (doc)#
bugprone-macro-parentheses [MEDIUM] (doc)#
bugprone-macro-repeated-side-effects [MEDIUM] (doc)#
bugprone-misplaced-operator-in-strlen-in-alloc [MEDIUM] (doc)#
(bugprone-misplaced-pointer-arithmetic-in-alloc) [MEDIUM] (doc)#
Disabled.
bugprone-misplaced-widening-cast [HIGH] (doc)#
bugprone-move-forwarding-reference [MEDIUM] (doc)#
bugprone-multiple-statement-macro [MEDIUM] (doc)#
(bugprone-no-escape) [undefined] (doc)#
To be added to .clang-tidy.
bugprone-not-null-terminated-result [MEDIUM] (doc)#
bugprone-parent-virtual-call [MEDIUM] (doc)#
bugprone-posix-return [undefined] (doc)#
(bugprone-redundant-branch-condition) [LOW] (doc)#
Disabled.
(bugprone-reserved-identifier) [LOW] (doc)#
Disabled because ROS 2 coding naming style for inclusion guards violates the rule by default.
(bugprone-signal-handler) [undefined] (doc)#
To be added to .clang-tidy.
bugprone-signed-char-misuse [MEDIUM] (doc)#
bugprone-sizeof-container [HIGH] (doc)#
bugprone-sizeof-expression [HIGH] (doc)#
(bugprone-spuriously-wake-up-functions) [undefined] (doc)#
bugprone-string-constructor [HIGH] (doc)#
bugprone-string-integer-assignment [LOW] (doc)#
bugprone-string-literal-with-embedded-nul [MEDIUM] (doc)#
bugprone-suspicious-enum-usage [HIGH] (doc)#
(bugprone-suspicious-include) [LOW] (doc)#
Disabled.
bugprone-suspicious-memset-usage [HIGH] (doc)#
bugprone-suspicious-missing-comma [HIGH] (doc)#
bugprone-suspicious-semicolon [HIGH] (doc)#
bugprone-suspicious-string-compare [MEDIUM] (doc)#
bugprone-swapped-arguments [HIGH] (doc)#
bugprone-terminating-continue [MEDIUM] (doc)#
bugprone-throw-keyword-missing [MEDIUM] (doc)#
bugprone-too-small-loop-variable [MEDIUM] (doc)#
bugprone-undefined-memory-manipulation [MEDIUM] (doc)#
bugprone-undelegated-constructor [MEDIUM] (doc)#
(bugprone-unhandled-exception-at-new) [undefined] (doc)#
To be added.
bugprone-unhandled-self-assignment [MEDIUM] (doc)#
bugprone-unused-raii [HIGH] (doc)#
bugprone-unused-return-value [MEDIUM] (doc)#
bugprone-use-after-move [HIGH] (doc)#
bugprone-virtual-near-miss [MEDIUM] (doc)#
cppcoreguidelines-*
#
We SHOULD fix the code problems detected by cppcoreguidelines-*
rules if these are not false-positives.
cppcoreguidelines-avoid-goto [STYLE] (doc)#
(cppcoreguidelines-avoid-non-const-global-variables) [LOW] (doc)#
Disabled.
cppcoreguidelines-init-variables [MEDIUM] (doc)#
cppcoreguidelines-interfaces-global-init [LOW] (doc)#
cppcoreguidelines-macro-usage [LOW] (doc)#
cppcoreguidelines-narrowing-conversions [MEDIUM] (doc)#
cppcoreguidelines-no-malloc [LOW] (doc)#
(cppcoreguidelines-owning-memory) [STYLE] (doc)#
Disabled.
cppcoreguidelines-prefer-member-initializer [STYLE] (doc)#
Disabled.
(cppcoreguidelines-pro-bounds-array-to-pointer-decay) [LOW] (doc)#
Disabled.
(cppcoreguidelines-pro-bounds-constant-array-index) [LOW] (doc)#
Disabled.
cppcoreguidelines-pro-bounds-pointer-arithmetic [LOW] (doc)#
cppcoreguidelines-pro-type-const-cast [LOW] (doc)#
cppcoreguidelines-pro-type-cstyle-cast [LOW] (doc)#
cppcoreguidelines-pro-type-member-init [LOW] (doc)#
cppcoreguidelines-pro-type-reinterpret-cast [LOW] (doc)#
cppcoreguidelines-pro-type-static-cast-downcast [LOW] (doc)#
cppcoreguidelines-pro-type-union-access [LOW] (doc)#
(cppcoreguidelines-pro-type-vararg) [LOW] (doc)#
Disabled.
cppcoreguidelines-slicing [LOW] (doc)#
cppcoreguidelines-special-member-functions [LOW] (doc)#
google-*
#
We SHOULD fix the code problems detected by google-*
rules if these are not false-positives.
google-build-explicit-make-pair [MEDIUM] (doc)#
google-build-namespaces [MEDIUM] (doc)#
google-build-using-namespace [STYLE] (doc)#
(google-default-arguments) [LOW] (doc)#
Disabled.
google-explicit-constructor [MEDIUM] (doc)#
google-global-names-in-headers [STYLE] (doc)#
(google-objc-avoid-nsobject-new) [undefined] (doc)#
Disabled.
(google-objc-avoid-throwing-exception) [undefined] (doc)#
Disabled.
(google-objc-function-naming) [undefined] (doc)#
Disabled.
(google-objc-global-variable-declaration) [undefined] (doc)#
Disabled.
(google-readability-avoid-underscore-in-googletest-name) [STYLE] (doc)#
(google-readability-casting) [LOW] (doc)#
Disabled.
(google-readability-todo) [STYLE] (doc)#
Disabled.
(google-runtime-int) [LOW] (doc)#
Disabled.
(google-runtime-operator) [MEDIUM] (doc)#
Disabled.
google-upgrade-googletest-case [STYLE] (doc)#
hicpp-*
#
We SHOULD fix the code problems detected by hicpp-*
rules if these are not false-positives.
hicpp-exception-baseclass [LOW] (doc)#
hicpp-multiway-paths-covered [STYLE] (doc)#
hicpp-no-assembler [LOW] (doc)#
hicpp-signed-bitwise [LOW] (doc)#
llvm-*
#
We MUST fix the code problems detected by llvm-*
rules if these are not false-positives.
llvm-namespace-comment [LOW] (doc)#
misc-*
#
We SHOULD fix the code problems detected by misc-*
rules if these are not false-positives.
misc-definitions-in-headers [MEDIUM] (doc)#
misc-misplaced-const [LOW] (doc)#
misc-new-delete-overloads [MEDIUM] (doc)#
misc-no-recursion [LOW] (doc)#
misc-non-copyable-objects [HIGH] (doc)#
(misc-non-private-member-variables-in-classes) [LOW] (doc)#
Disabled because of annoyance.
misc-redundant-expression [MEDIUM] (doc)#
MUST.
misc-static-assert [LOW] (doc)#
misc-throw-by-value-catch-by-reference [HIGH] (doc)#
MUST.
misc-unconventional-assign-operator [MEDIUM] (doc)#
misc-uniqueptr-reset-release [MEDIUM] (doc)#
misc-unused-alias-decls [LOW] (doc)#
MUST.
misc-unused-parameters [LOW] (doc)#
MUST.
misc-unused-using-decls [LOW] (doc)#
MUST.
modernize-*
#
We SHOULD fix the code problems detected by modernize-*
rules if these are not false-positives.
(modernize-avoid-bind) [STYLE] (doc)#
Disabled because of incompatibility with ROS.
modernize-avoid-c-arrays [LOW] (doc)#
modernize-concat-nested-namespaces [STYLE] (doc)#
modernize-deprecated-headers [LOW] (doc)#
MUST.
modernize-deprecated-ios-base-aliases [LOW] (doc)#
modernize-loop-convert [STYLE] (doc)#
modernize-make-shared [LOW] (doc)#
modernize-make-unique [LOW] (doc)#
modernize-pass-by-value [LOW] (doc)#
modernize-raw-string-literal [STYLE] (doc)#
modernize-redundant-void-arg [STYLE] (doc)#
MUST.
modernize-replace-auto-ptr [LOW] (doc)#
modernize-replace-disallow-copy-and-assign-macro [LOW] (doc)#
modernize-replace-random-shuffle [LOW] (doc)#
modernize-return-braced-init-list [STYLE] (doc)#
modernize-shrink-to-fit [STYLE] (doc)#
modernize-unary-static-assert [STYLE] (doc)#
modernize-use-auto [STYLE] (doc)#
modernize-use-bool-literals [STYLE] (doc)#
MUST.
modernize-use-default-member-init [STYLE] (doc)#
modernize-use-emplace [STYLE] (doc)#
MUST.
modernize-use-equals-default [STYLE] (doc)#
MUST.
modernize-use-equals-delete [STYLE] (doc)#
MUST.
modernize-use-nodiscard [LOW] (doc)#
We SHOULD follow the rule if we use C++17.
modernize-use-noexcept [LOW] (doc)#
modernize-use-nullptr [LOW] (doc)#
MUST.
modernize-use-override [LOW] (doc)#
MUST.
(modernize-use-trailing-return-type) [LOW] (doc)#
Disabled.
modernize-use-transparent-functors [LOW] (doc)#
modernize-use-uncaught-exceptions [STYLE] (doc)#
modernize-use-using [STYLE] (doc)#
MUST.
openmp-*
#
openmp-use-default-none [undefined] (doc)#
performance-*
#
We SHOULD fix the code problems detected by performance-*
rules if these are not false-positives.
performance-faster-string-find [LOW] (doc)#
MUST.
performance-for-range-copy [LOW] (doc)#
performance-implicit-conversion-in-loop [LOW] (doc)#
performance-inefficient-algorithm [MEDIUM] (doc)#
MUST.
performance-inefficient-string-concatenation [LOW] (doc)#
performance-inefficient-vector-operation [LOW] (doc)#
performance-move-const-arg [MEDIUM] (doc)#
performance-move-constructor-init [MEDIUM] (doc)#
performance-no-automatic-move [LOW] (doc)#
performance-no-int-to-ptr [LOW] (doc)#
performance-noexcept-move-constructor [MEDIUM] (doc)#
performance-trivially-destructible [LOW] (doc)#
performance-type-promotion-in-math-fn [LOW] (doc)#
performance-unnecessary-copy-initialization [LOW] (doc)#
performance-unnecessary-value-param [LOW] (doc)#
We MAY ignore the warning safely if Ptr, SharedPtr, and ConstSharedPtr are pointed out as follows (which is currently suppressed by the AllowedTypes option in .clang-tidy).
src/autoware/AutowareArchitectureProposal.iv/planning/scenario_planning/lane_driving/motion_planning/obstacle_stop_planner/src/adaptive_cruise_control.cpp:176:58:
warning: the const qualified parameter 'current_velocity_ptr' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]
const geometry_msgs::msg::TwistStamped::ConstSharedPtr current_velocity_ptr, bool _ need_to_stop,
^
&
portability-*
#
portability-simd-intrinsics [STYLE] (doc)#
readability-*
#
We SHOULD fix the code problems detected by bugprone-*
rules if these are not false-positives.
(readability-avoid-const-params-in-decls) [STYLE] (doc)#
Disabled.
(readability-braces-around-statements) [STYLE] (doc)#
Disabled.
readability-const-return-type [LOW] (doc)#
readability-container-size-empty [STYLE] (doc)#
readability-convert-member-functions-to-static [STYLE] (doc)#
Optional. It depends on the design of the class. We MAY ignore this warning safely.
readability-delete-null-pointer [STYLE] (doc)#
readability-else-after-return [STYLE] (doc)#
readability-function-cognitive-complexity [STYLE] (doc)#
(readability-function-size) [STYLE] (doc)#
(readability-identifier-length) [STYLE] (doc)#
To be added.
(readability-identifier-naming) [STYLE] (doc)#
To be added.
(readability-implicit-bool-conversion) [STYLE] (doc)#
readability-inconsistent-declaration-parameter-name [STYLE] (doc)#
readability-isolate-declaration [STYLE] (doc)#
(readability-magic-numbers) [STYLE] (doc)#
Disabled because of annoyance.
readability-make-member-function-const [STYLE] (doc)#
MUST.
readability-misleading-indentation [LOW] (doc)#
MUST.
readability-misplaced-array-index [STYLE] (doc)#
MUST.
(readability-named-parameter) [STYLE] (doc)#
readability-non-const-parameter [STYLE] (doc)#
(readability-qualified-auto) [LOW] (doc)#
To be added.
readability-redundant-access-specifiers [STYLE] (doc)#
readability-redundant-control-flow [STYLE] (doc)#
readability-redundant-declaration [STYLE] (doc)#
readability-redundant-function-ptr-dereference [STYLE] (doc)#
readability-redundant-member-init [STYLE] (doc)#
(readability-redundant-preprocessor) [STYLE] (doc)#
readability-redundant-smartptr-get [STYLE] (doc)#
readability-redundant-string-cstr [STYLE] (doc)#
readability-redundant-string-init [STYLE] (doc)#
readability-simplify-boolean-expr [MEDIUM] (doc)#
readability-simplify-subscript-expr [STYLE] (doc)#
readability-static-accessed-through-instance [STYLE] (doc)#
readability-static-definition-in-anonymous-namespace [STYLE] (doc)#
readability-string-compare [LOW] (doc)#
MUST.
(readability-suspicious-call-argument) [LOW] (doc)#
Disabled.
readability-uniqueptr-delete-release [STYLE] (doc)#
(readability-uppercase-literal-suffix) [STYLE] (doc)#
Disabled temporarily. Will be enabled to merge the code to Autoware.Auto.
readability-use-anyofallof [STYLE] (doc)#
Optional. We MAY ignore the warning safely.