From c5f4a1db71becd15546b77862e148fd3ac0ada61 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sun, 1 Dec 2024 17:09:58 +0000 Subject: [PATCH] build: fix building with clang --- .github/workflows/check-formatting.yml | 28 ++++++++++++++++++++++++++ scripts/check-format.sh | 8 ++++++++ src/client/loader/component_loader.hpp | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check-formatting.yml create mode 100755 scripts/check-format.sh diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml new file mode 100644 index 0000000..3f03f77 --- /dev/null +++ b/.github/workflows/check-formatting.yml @@ -0,0 +1,28 @@ +name: check-formatting + +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + types: [opened, synchronize, reopened] + +jobs: + check-formatting: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@main + + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v2.0.2 + with: + version: "17.0" + + - name: Test formatting for all files + working-directory: ${{ github.workspace }} + run: | + export CLANG_FORMAT_BIN="${LLVM_PATH}/bin/clang-format" + ./scripts/check-format.sh diff --git a/scripts/check-format.sh b/scripts/check-format.sh new file mode 100755 index 0000000..349d7b3 --- /dev/null +++ b/scripts/check-format.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Go to repository root +cd "$(dirname "$0")/.." || exit 2 + +CLANG_FORMAT_BIN="${CLANG_FORMAT_BIN:-clang-format}" + +find ./src -iname '*.hpp' -o -iname '*.cpp' | xargs $CLANG_FORMAT_BIN -Werror -ferror-limit=1 --dry-run diff --git a/src/client/loader/component_loader.hpp b/src/client/loader/component_loader.hpp index 5d94b52..4dee3b8 100644 --- a/src/client/loader/component_loader.hpp +++ b/src/client/loader/component_loader.hpp @@ -19,8 +19,8 @@ public: template static T* get() { for (const auto& component_ : get_components()) { - if (typeid(*component_.get()) == typeid(T)) { - return reinterpret_cast(component_.get()); + if (auto c = dynamic_cast(component_.get())) { + return c; } }