Skip to content

Commit

Permalink
Upgrade clang-tidy to LLVM 18, and fix (some) newly firing lints (Cle…
Browse files Browse the repository at this point in the history
…verRaven#79633)

* Upgrade clang-tidy to llvm-18

- fix compilation issues
- update the CI
- drive-by change: bump the displayed "most time consuming checks" from
  top 10 to top 30

* Make .clang-tidy use structured list for checks

instead of a single string that relies on `\` with
no trailing whitespace for line joining.
Both because the \ thing is bugprone, but mostly because
i want to add extra comments about *why* the checks are
disabled

* Shuffle comments around to be closer to the thing they are commenting on

* Disable newly discovered firing checks

This partially defeats the whole point of update,
but maybe that's still worth it.

Improved existing checks:
modernize-make-shared
readability-redundant-member-init

Newly introduced checks:
bugprone-chained-comparison
bugprone-multi-level-implicit-pointer-conversion
bugprone-optional-value-conversion
bugprone-unused-local-non-trivial-variable
clang-analyzer-optin.core.EnumCastOutOfRange
performance-enum-size
readability-avoid-nested-conditional-operator
readability-avoid-return-with-void-value
readability-redundant-casting
readability-redundant-inline-specifier
readability-reference-to-constructed-temporary

* Reenable and fix modernize-make-shared

https://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html
the new check is the x.reset(new T(args)) => x=make_shared::<T>(args) form

example error:
  ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/item_location.cpp:838:13: error: use std::make_shared instead [modernize-make-shared,-warnings-as-errors]
    9 |         ptr.reset( new impl::item_on_person( who_id, idx ) );
      |            ~^~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~~             ~
      |             = std::make_shared<impl::item_on_person>

* Re-enable and fix readability-redundant-member-init lint

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Sample error:
 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/effect_source.h:47:41: error: initializer for member 'fac' is redundant [readability-redundant-member-init,-warnings-as-errors]
    47 |         std::optional<faction_id> fac = faction_id();
       |                                       ~~^~~~~~~~~~~~

* Enable and fix bugprone-optional-value-conversion lint

https://clang.llvm.org/extra/clang-tidy/checks/bugprone/optional-value-conversion.html

Sample error:
 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/mission_util.cpp:182:67: error: conversion from 'std::optional<abstract_var_info<std::basic_string<char>>>' into 'abstract_var_info<std::basic_string<char>>' and back into 'std::optional<abstract_var_info<std::basic_string<char>>>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion,-warnings-as-errors]
   182 |         return project_to<coords::omt>( get_tripoint_ms_from_var( params.target_var.value(), d, false ) );
       |                                                                   ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/mission_util.cpp:182:85: note: remove call to 'value' to silence this warning
   182 |         return project_to<coords::omt>( get_tripoint_ms_from_var( params.target_var.value(), d, false ) );
       |                                                                                    ~^~~~~~~

* Fix and reenable bugprone-chained-comparison

https://clang.llvm.org/extra/clang-tidy/checks/bugprone/chained-comparison.html

It only crops up in tests due to how catch2 works.

Catch2 has silenced the lint on their end in
catchorg/Catch2@1078e7e

This commit mirrors the upstream change

Example error:
 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/zones_custom_test.cpp:56:9: error: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison,-warnings-as-errors]
    56 |         REQUIRE( zmgr.get_near_zone_type_for_item( hammer, where ) == zone_type_LOOT_CUSTOM );
       |         ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:17636:24: note: expanded from macro 'REQUIRE'
  17636 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__  )
        |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:2706:47: note: expanded from macro 'INTERNAL_CATCH_TEST'
  2706 |             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
       |                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/zones_custom_test.cpp:56:9: note: operand 'v0' is here
    56 |         REQUIRE( zmgr.get_near_zone_type_for_item( hammer, where ) == zone_type_LOOT_CUSTOM );
       |         ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:17636:24: note: expanded from macro 'REQUIRE'
  17636 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__  )
        |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:2706:47: note: expanded from macro 'INTERNAL_CATCH_TEST'
  2706 |             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
       |                                               ^~~~~~~~~~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/zones_custom_test.cpp:56:18: note: operand 'v1' is here
    56 |         REQUIRE( zmgr.get_near_zone_type_for_item( hammer, where ) == zone_type_LOOT_CUSTOM );
       |                  ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:17636:90: note: expanded from macro 'REQUIRE'
  17636 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__  )
        |                                                                                          ^~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:2706:70: note: expanded from macro 'INTERNAL_CATCH_TEST'
  2706 |             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
       |                                                                      ^~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/zones_custom_test.cpp:56:71: note: operand 'v2' is here
    56 |         REQUIRE( zmgr.get_near_zone_type_for_item( hammer, where ) == zone_type_LOOT_CUSTOM );
       |                                                                       ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:17636:90: note: expanded from macro 'REQUIRE'
  17636 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__  )
        |                                                                                          ^~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/tests/catch/catch.hpp:2706:70: note: expanded from macro 'INTERNAL_CATCH_TEST'
  2706 |             catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
       |                                                                      ^~~~~~~~~~~

* Fix and re-enable readability-reference-to-constructed-temporary

https://clang.llvm.org/extra/clang-tidy/checks/readability/reference-to-constructed-temporary.html
Example error:
 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/melee.cpp:1809:32: error: reference variable 'dest' extends the lifetime of a just-constructed temporary object 'const tripoint_bub_ms' (aka 'const coords::coord_point_ob<tripoint, coords::origin::reality_bubble, coords::scale::map_square>'), consider changing reference to value [readability-reference-to-constructed-temporary,-warnings-as-errors]
  1809 |         const tripoint_bub_ms &dest{ new_, b.z()};
       |

* Fix and reenable readability-avoid-return-with-void-value

https://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-return-with-void-value.html

Example error:

 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/map.h:2397:13: error: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value,-warnings-as-errors]
  2397 |             return map::i_clear( rebase_bub( p ) );
       |

* Triage readability-redundant-inline-specifier as not desirable

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-inline-specifier.html
Sample error:
 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/point.h:33:5: error: function 'is_invalid' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier,-warnings-as-errors]
    33 |     inline bool is_invalid() const {
       |     ^~~~~~

Reasoning to keep disabled in the comments

* Triage clang-analyzer-optin.core.EnumCastOutOfRange as not desirable

https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer/optin.core.EnumCastOutOfRange.html

Rationale in comments.

Example error:

 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/enum_traits.h:99:12: error: The value '7' provided to the cast expression is not in the valid range of values for 'part_status_flag' [clang-analyzer-optin.core.EnumCastOutOfRange,-warnings-as-errors]
    99 |     return static_cast<E>( static_cast<I>( l ) | static_cast<I>( r ) );
       |            ^
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/vehicle.h:100:12: note: enum declared here
   100 | enum class part_status_flag : int {
       | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
   101 |     any = 0,
       |     ~~~~~~~~
   102 |     working = 1 << 0,
       |     ~~~~~~~~~~~~~~~~~
   103 |     available = 1 << 1,
       |     ~~~~~~~~~~~~~~~~~~~
   104 |     enabled = 1 << 2
       |     ~~~~~~~~~~~~~~~~
   105 | };
       | ~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/vehicle.cpp:3124:44: note: Calling 'operator|<part_status_flag, void>'
  3124 |             static_cast<part_status_flag>( part_status_flag::enabled |
       |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  3125 |                                            part_status_flag::working |
       |                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3126 |                                            part_status_flag::available ) );
       |                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/enum_traits.h:99:12: note: The value '7' provided to the cast expression is not in the valid range of values for 'part_status_flag'
    99 |     return static_cast<E>( static_cast<I>( l ) | static_cast<I>( r ) );
       |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Mark the remaining lints as "maybe some other day"

Lints in question:
  bugprone-multi-level-implicit-pointer-conversion
  bugprone-unused-local-non-trivial-variable
  performance-enum-size
  readability-avoid-nested-conditional-operator
  readability-redundant-casting

They look reasonable but I can't really deal with them right now.

* Fix readability-container-size-empty (and keep it enabled)

https://clang.llvm.org/extra/clang-tidy/checks/readability/container-size-empty.html

Error: /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/climbing.cpp:222:13: error: the 'empty' method should be used to check for emptiness instead of 'length' [readability-container-size-empty,-warnings-as-errors]
  222 |         if( menu_hotkey_str.length() ) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
      |             !menu_hotkey_str.empty()

* Disable two lints for performance reasons.

Lints in question:
  misc-unused-using-decls
  modernize-replace-auto-ptr

These are in top-10 most expensive checks.

For context: here's the profiling data when running clang-tidy
on ~most of the codebase (as seen in the CI in one of the versions of the current PR):
{
  "time.clang-tidy.misc-unused-using-decls.wall": 1094.7915439605713,
  "time.clang-tidy.bugprone-stringview-nullptr.wall": 866.0817050933838,
  "time.clang-tidy.cata-redundant-parentheses.wall": 839.2004644870758,
  "time.clang-tidy.modernize-type-traits.wall": 814.9849390983582,
  "time.clang-tidy.bugprone-use-after-move.wall": 694.5256803035736,
  "time.clang-tidy.modernize-use-transparent-functors.wall": 670.7836837768555,
  "time.clang-tidy.bugprone-standalone-empty.wall": 600.5903759002686,
  "time.clang-tidy.modernize-replace-auto-ptr.wall": 580.4591262340546,
  "time.clang-tidy.modernize-deprecated-ios-base-aliases.wall": 566.2826192378998,
  "time.clang-tidy.bugprone-reserved-identifier.wall": 558.5143051147461,
  "time.clang-tidy.modernize-avoid-c-arrays.wall": 545.1163799762726,
  "time.clang-tidy.modernize-use-using.wall": 539.6424849033356,
  "time.clang-tidy.performance-unnecessary-value-param.wall": 471.33301615715027,
  "time.clang-tidy.readability-non-const-parameter.wall": 440.45192885398865,
  "time.clang-tidy.cert-dcl58-cpp.wall": 421.88030886650085,
  "time.clang-tidy.cata-translate-string-literal.wall": 390.8441689014435,
  "time.clang-tidy.cata-static-initialization-order.wall": 388.08465909957886,
  "time.clang-tidy.readability-redundant-declaration.wall": 381.59097266197205,
  "time.clang-tidy.cert-dcl16-c.wall": 362.8544645309448,
  "time.clang-tidy.readability-container-size-empty.wall": 358.62095737457275,
  "time.clang-tidy.modernize-use-nullptr.wall": 352.8454167842865,
  "time.clang-tidy.bugprone-suspicious-string-compare.wall": 350.5792667865753,
  "time.clang-tidy.misc-misleading-identifier.wall": 346.3509900569916,
  "time.clang-tidy.misc-definitions-in-headers.wall": 330.5536653995514,
  "time.clang-tidy.readability-redundant-control-flow.wall": 329.31720495224,
  "time.clang-tidy.bugprone-infinite-loop.wall": 319.4184067249298,
  "time.clang-tidy.bugprone-unused-return-value.wall": 306.18062829971313,
  "time.clang-tidy.performance-move-const-arg.wall": 300.217401266098,
  "time.clang-tidy.bugprone-assert-side-effect.wall": 298.9822633266449,
  "time.clang-tidy.bugprone-multiple-statement-macro.wall": 297.0318651199341
}

* Fix and re-enable bugprone-multi-level-implicit-pointer-conversion

https://clang.llvm.org/extra/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.html

Two points of occurence, both are about passing T** to memX() functions.
The usage is intended, and correct, so silence.
Although perhaps we could add an explicit `reinterpret_cast<void*>`
there, but I'm not sure it's valuable.

 ##[error]/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/cata_bitset.h:182:25: error: multilevel pointer conversion from 'block_t **' (aka 'unsigned long **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion,-warnings-as-errors]
  182 |                 memcpy( &ret, &storage_, sizeof( storage_ ) );
      |
  • Loading branch information
moxian authored Feb 13, 2025
1 parent 723f7d2 commit 26712e3
Show file tree
Hide file tree
Showing 51 changed files with 230 additions and 210 deletions.
207 changes: 110 additions & 97 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,117 @@
# this codebase and we do not intend to fix. The disabled checks appearing
# thereafter in a separate alphabetical list have yet to be triaged. We may
# fix their errors or recategorise them as checks we don't care about.
#
# Comments on the checks we have decided are not worthwhile:
#
# * bugprone-throw-keyword-missing
# This check is too time consuming. Disable it for now to save CI time.
#
# * cert-dcl21-cpp (postfix operator++ and operator-- should return const objects)
# This is an unconventional code style, and conflicts with
# readability-const-return-type.
#
# * cert-env33-c (calls to system, popen)
# Unlikely to catch bugs, and using system is convenient for portability.
#
# * cert-dcl37-c and cert-dcl-51-cpp (reserved identifiers)
# These two checks are aliases for bugprone-reserved-identifier.
# Don't repeatedly run the same check for three times.
#
# * cert-err58-cpp (exceptions from static variable declarations)
# We have lots of memory allocations in static variable declarations, and
# that's fine.
#
# * clang-analyzer-core.{DivideZero,NonNullParamChecker,UndefinedBinaryOperatorResult}
# * clang-analyzer-cplusplus.NewDelete
# They report too many false positives.
#
# * modernize-use-auto
# We prefer an almost-always-avoid-auto style.
#
# * modernize-use-trailing-return-type
# An arbitrary style convention we haven't adopted.
#
# * readability-identifier-naming
# We are not enforcing a standard identifier naming scheme in the code base.
# This check does not bring much value at the moment and consumes a lot of CPU time.

Checks: "\
bugprone-*,\
cata-*,\
cert-*,\
-cert-dcl21-cpp,\
-cert-env33-c,\
-cert-dcl37-c,\
-cert-dcl51-cpp,\
-cert-err58-cpp,\
-clang-analyzer-core.CallAndMessage,\
-clang-analyzer-core.DivideZero,\
-clang-analyzer-core.NonNullParamChecker,\
-clang-analyzer-core.UndefinedBinaryOperatorResult,\
-clang-analyzer-cplusplus.NewDelete,\
clang-diagnostic-*,\
cppcoreguidelines-slicing,\
google-explicit-constructor,\
llvm-namespace-comment,\
misc-*,\
modernize-*,\
-modernize-use-auto,\
-modernize-use-trailing-return-type,\
performance-*,\
readability-*,\
-bugprone-assignment-in-if-condition,\
-bugprone-easily-swappable-parameters,\
-bugprone-empty-catch,\
-bugprone-implicit-widening-of-multiplication-result,\
-bugprone-narrowing-conversions,\
-bugprone-switch-missing-default-case,\
-bugprone-throw-keyword-missing,\
-bugprone-unchecked-optional-access,\
-bugprone-unhandled-exception-at-new,\
-misc-confusable-identifiers,\
-misc-const-correctness,\
-misc-header-include-cycle,\
-misc-include-cleaner,\
-misc-no-recursion,\
-misc-non-private-member-variables-in-classes,\
-misc-use-anonymous-namespace,\
-modernize-concat-nested-namespaces,\
-modernize-macro-to-enum,\
-modernize-pass-by-value,\
-modernize-return-braced-init-list,\
-modernize-use-default-member-init,\
-modernize-use-nodiscard,\
-performance-avoid-endl,\
-performance-noexcept-swap,\
-performance-no-automatic-move,\
-readability-avoid-unconditional-preprocessor-if,\
-readability-container-data-pointer,\
-readability-convert-member-functions-to-static,\
-readability-else-after-return,\
-readability-function-cognitive-complexity,\
-readability-identifier-length,\
-readability-identifier-naming,\
-readability-implicit-bool-conversion,\
-readability-magic-numbers,\
-readability-named-parameter,\
-readability-simplify-boolean-expr,\
-readability-suspicious-call-argument,\
-readability-use-anyofallof,\
"
Checks: [
bugprone-*,
# This check is too time consuming. Disable it for now to save CI time.
-bugprone-throw-keyword-missing,
cata-*,
cert-*,
# * cert-dcl21-cpp (postfix operator++ and operator-- should return const objects)
# This is an unconventional code style, and conflicts with
# readability-const-return-type.
-cert-dcl21-cpp,
# * cert-env33-c (calls to system, popen)
# Unlikely to catch bugs, and using system is convenient for portability.
-cert-env33-c,
# * cert-dcl37-c and cert-dcl-51-cpp (reserved identifiers)
# These two checks are aliases for bugprone-reserved-identifier.
# Don't repeatedly run the same check for three times.
-cert-dcl37-c,
-cert-dcl51-cpp,
# * cert-err58-cpp (exceptions from static variable declarations)
# We have lots of memory allocations in static variable declarations, and
# that's fine.
-cert-err58-cpp,
# * clang-analyzer-core.{DivideZero,NonNullParamChecker,UndefinedBinaryOperatorResult}
# * clang-analyzer-cplusplus.NewDelete
# They report too many false positives.
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-core.DivideZero,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
-clang-analyzer-cplusplus.NewDelete,
# We often use enums as bitsets and do things like `enum::A | enum::B`
# which is explicitly unsupported by this check, and it is officially recommended to disable
# this lint for project that use such patterns.
-clang-analyzer-optin.core.EnumCastOutOfRange,
clang-diagnostic-*,
cppcoreguidelines-slicing,
google-explicit-constructor,
llvm-namespace-comment,
misc-*,
# Extremely expensive, and we are not using `using` anyway, so it's not catching anything.
-misc-unused-using-decls,
modernize-*,
# Rather expensive check, and it is unlikely that somebody
# would *want* to use std::auto_ptr in %CURRENT_YEAR% (2025+) when unique_ptr is both better
# and is a de-facto default in the codebase already.
-modernize-replace-auto-ptr,
# * modernize-use-auto
# We prefer an almost-always-avoid-auto style.
-modernize-use-auto,
# * modernize-use-trailing-return-type
# An arbitrary style convention we haven't adopted.
-modernize-use-trailing-return-type,
performance-*,
readability-*,
# * readability-identifier-naming
# We are not enforcing a standard identifier naming scheme in the code base.
# This check does not bring much value at the moment and consumes a lot of CPU time.
-readability-identifier-length,
-readability-identifier-naming,
# disabled due to behaviour change between pre-module and post-module world.
# Reevaluate in 2027(?) when the code is sufficiently migrated to C++20 modules
# or when there is a decision not perform the migration
-readability-redundant-inline-specifier,

# ==== Untriaged checks follow ====
# Either fix the code and re-enable the check,
# or add a good comment and move to the appropriate section above.
# Silencing the existing errors with a //NOLINT does count as a "fix", as that still
# prevents new issues from cropping up.
-bugprone-assignment-in-if-condition,
-bugprone-easily-swappable-parameters,
-bugprone-empty-catch,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-bugprone-switch-missing-default-case,
-bugprone-unchecked-optional-access,
-bugprone-unhandled-exception-at-new,
-bugprone-unused-local-non-trivial-variable, # great lint, but hard to fix
-misc-confusable-identifiers,
-misc-const-correctness,
-misc-header-include-cycle,
-misc-include-cleaner,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-use-anonymous-namespace,
-modernize-concat-nested-namespaces,
-modernize-macro-to-enum,
-modernize-pass-by-value,
-modernize-return-braced-init-list,
-modernize-use-default-member-init,
-modernize-use-nodiscard,
-performance-avoid-endl,
-performance-enum-size, # untriaged since upgrade to LLVM 18
-performance-noexcept-swap,
-performance-no-automatic-move,
-readability-avoid-nested-conditional-operator, # great lint, but hard to fix
-readability-avoid-unconditional-preprocessor-if,
-readability-container-data-pointer,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-implicit-bool-conversion,
-readability-magic-numbers,
-readability-named-parameter,
-readability-redundant-casting, # probably good lint, just needs fixing
-readability-simplify-boolean-expr,
-readability-suspicious-call-argument,
-readability-use-anyofallof,
]

WarningsAsErrors: '*'
HeaderFilterRegex: '(src|test|tools).*'
FormatStyle: none
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Clang-tidy 17
name: Clang-tidy 18

on:
push:
Expand Down Expand Up @@ -36,13 +36,13 @@ jobs:
fail-fast: true
runs-on: ubuntu-24.04
env:
COMPILER: clang++-17
COMPILER: clang++-18
steps:
- name: install LLVM 17
- name: install LLVM 18
if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' && github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
run: |
sudo apt-get update
sudo apt install llvm-17 llvm-17-dev llvm-17-tools clang-17 clang-tidy-17 clang-tools-17 libclang-17-dev
sudo apt install llvm-18 llvm-18-dev llvm-18-tools clang-18 clang-tidy-18 clang-tools-18 libclang-18-dev
sudo apt install python3-pip ninja-build cmake
pip3 install --user lit
- name: checkout repository
Expand Down Expand Up @@ -74,8 +74,8 @@ jobs:

runs-on: ubuntu-24.04
env:
COMPILER: clang++-17
CATA_CLANG_TIDY: clang-tidy-17
COMPILER: clang++-18
CATA_CLANG_TIDY: clang-tidy-18
CATA_CLANG_TIDY_SUBSET: ${{ matrix.subset }}
TILES: 1
SOUND: 1
Expand All @@ -85,7 +85,7 @@ jobs:
if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' && github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
run: |
sudo apt-get update
sudo apt install clang-17 clang-tidy-17 cmake ccache jq
sudo apt install clang-18 clang-tidy-18 cmake ccache jq
sudo apt install libflac-dev libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev gettext
- name: checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
run: | # the folder may not exist if there is no file to analyze
if [ -d clang-tidy-trace ]
then
jq -n 'reduce(inputs.profile | to_entries[]) as {$key,$value} ({}; .[$key] += $value) | with_entries(select(.key|contains(".wall"))) | to_entries | sort_by(.value) | reverse | .[0:10] | from_entries' clang-tidy-trace/*.json
jq -n 'reduce(inputs.profile | to_entries[]) as {$key,$value} ({}; .[$key] += $value) | with_entries(select(.key|contains(".wall"))) | to_entries | sort_by(.value) | reverse | .[0:30] | from_entries' clang-tidy-trace/*.json
else
echo "clang-tidy-trace folder not found."
fi
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@
"C_Cpp.formatting": "disabled",
"astyle.astylerc": "${workspaceRoot}/.astylerc",
"files.associations": {
"vector": "cpp"
".clang-tidy": "yaml",
}
}
6 changes: 3 additions & 3 deletions build-scripts/clang-tidy-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cmake_extra_opts=()
cmake_extra_opts+=("-DCATA_CLANG_TIDY_PLUGIN=ON")
# Need to specify the particular LLVM / Clang versions to use, lest it
# use the older LLVM that comes by default on Ubuntu.
cmake_extra_opts+=("-DLLVM_DIR=/usr/lib/llvm-17/lib/cmake/llvm")
cmake_extra_opts+=("-DClang_DIR=/usr/lib/llvm-17/lib/cmake/clang")
cmake_extra_opts+=("-DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm")
cmake_extra_opts+=("-DClang_DIR=/usr/lib/llvm-18/lib/cmake/clang")


mkdir -p build
Expand All @@ -33,7 +33,7 @@ echo "Compiling clang-tidy plugin"
make -j$num_jobs CataAnalyzerPlugin
#export PATH=$PWD/tools/clang-tidy-plugin/clang-tidy-plugin-support/bin:$PATH
# add FileCheck to the search path
export PATH=/usr/lib/llvm-17/bin:$PATH
export PATH=/usr/lib/llvm-18/bin:$PATH
if ! which FileCheck
then
echo "Missing FileCheck"
Expand Down
6 changes: 3 additions & 3 deletions src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class aim_activity_actor : public activity_actor
bool should_unload_RAS = false;
bool snap_to_target = false;
/* Item location for RAS weapon reload */
item_location reload_loc = item_location();
item_location reload_loc;
bool shifting_view = false;
tripoint_rel_ms initial_view_offset;
/** Target UI requested to abort aiming */
Expand Down Expand Up @@ -1428,8 +1428,8 @@ class milk_activity_actor : public activity_actor

private:
int total_moves {};
std::vector<tripoint_abs_ms> monster_coords {};
std::vector<std::string> string_values {};
std::vector<tripoint_abs_ms> monster_coords;
std::vector<std::string> string_values;
};

class shearing_activity_actor : public activity_actor
Expand Down
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void put_into_vehicle_or_drop( Character &you, item_drop_reason reason,
{
map &here = get_map();

return put_into_vehicle_or_drop( you, reason, items, &here, you.pos_bub( &here ) );
put_into_vehicle_or_drop( you, reason, items, &here, you.pos_bub( &here ) );
}

void put_into_vehicle_or_drop( Character &you, item_drop_reason reason,
Expand Down
3 changes: 2 additions & 1 deletion src/cata_bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ void tiny_bitset::resize_heap( size_t requested_bits ) noexcept

void tiny_bitset::set_storage( block_t *data )
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
memcpy( &storage_, &data, sizeof( data ) );
}
}
1 change: 1 addition & 0 deletions src/cata_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class tiny_bitset
// The hashtag blessed UB-avoiding way of type punning a pointer
// out of an integer.
block_t *ret;
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
memcpy( &ret, &storage_, sizeof( storage_ ) );
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ tileset::find_tile_type_by_season( const std::string &id, season_type season ) c
}
const tileset::season_tile_value &res = iter->second;
if( res.season_tile ) {
return *res.season_tile;
return res.season_tile;
} else if( res.default_tile ) { // can skip this check, but just in case
return tile_lookup_res( iter->first, *res.default_tile );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character_modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct character_modifier {
mod_type limbscore_modop = MULT;
std::vector<std::pair<character_modifier_id, mod_id>> src;
body_part_type::type limbtype = body_part_type::type::num_types;
translation desc = translation();
translation desc;
mod_type modtype = mod_type::NONE;
float max_val = 0.0f;
float min_val = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/climbing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void climbing_aid::down_t::deserialize( const JsonObject &jo )
jo.throw_error( str_cat( "failed to read optional member \"menu_hotkey\"" ) );
}
}
if( menu_hotkey_str.length() ) {
if( !menu_hotkey_str.empty() ) {
menu_hotkey = std::uint8_t( menu_hotkey_str[ 0 ] );
}

Expand Down
2 changes: 1 addition & 1 deletion src/construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class nc_color;

struct partial_con {
int counter = 0;
std::list<item> components = {};
std::list<item> components;
construction_id id = construction_id( -1 );
};

Expand Down
Loading

0 comments on commit 26712e3

Please sign in to comment.