From 055737b4cfdae09dc7735483e21999d68add9804 Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Sun, 28 Apr 2024 09:10:57 +0200 Subject: [PATCH] ci: Add clang-tidy check for C-style casts (#3149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a new clang-tidy check. Necessary changes and more details in the PR below. blocked by: - https://github.com/acts-project/acts/pull/3146 ## Sample ``` ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexF─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexFi │ │ nderTests.cpp:47:10 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 47 | return (int)(gen() / 4294967296. * (to - from) + from); │ │ │ │ | ^~~~~ │ │ │ │ | static_cast │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialCompositio─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialComposition │ │ Tests.cpp:28:26 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 28 | float carbonFraction = float(carbonWeight) / 255u; │ │ │ │ | ^~~~~ │ │ │ │ | static_cast │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ``` --- .clang-tidy | 1 + CI/clang_tidy/limits.yml | 1 + cmake/ActsStaticAnalysis.cmake | 1 + 3 files changed, 3 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 2f3cdc1e296..8a4f9b20918 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,7 @@ Checks: '-*, \ clang-analyzer-optin.cplusplus.UninitializedObject, \ cppcoreguidelines-init-variables, \ cppcoreguidelines-pro-type-member-init, \ + google-readability-casting, \ modernize-concat-nested-namespaces, \ modernize-use-equals-default, \ modernize-use-default-member-init, \ diff --git a/CI/clang_tidy/limits.yml b/CI/clang_tidy/limits.yml index 6f7fe8759cb..9c5e59cb2af 100644 --- a/CI/clang_tidy/limits.yml +++ b/CI/clang_tidy/limits.yml @@ -3,6 +3,7 @@ limits: "clang-diagnostic-error": 0 "cppcoreguidelines-init-variables": 0 "cppcoreguidelines-pro-type-member-init": 0 + "google-readability-casting": 0 "modernize-concat-nested-namespaces": 0 "modernize-use-equals-default": 0 "modernize-use-default-member-init": 0 diff --git a/cmake/ActsStaticAnalysis.cmake b/cmake/ActsStaticAnalysis.cmake index 6c82dc86b49..5b1541035ff 100644 --- a/cmake/ActsStaticAnalysis.cmake +++ b/cmake/ActsStaticAnalysis.cmake @@ -11,6 +11,7 @@ if(ACTS_RUN_CLANG_TIDY) list(APPEND _chks "clang-analyzer-optin.cplusplus.UninitializedObject") list(APPEND _chks "cppcoreguidelines-init-variables") list(APPEND _chks "cppcoreguidelines-pro-type-member-init") + list(APPEND _chks "google-readability-casting") list(APPEND _chks "modernize-concat-nested-namespaces") list(APPEND _chks "modernize-use-equals-default") list(APPEND _chks "modernize-use-default-member-init")