clang-tidy at zero warnings, no C-style casts, Windows compile databases #3

Closed
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:47 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

Lint at zero from the start costs a little every day; lint turned on later cost the fork a repo-wide cast pass and a long tail of fixes. Windows-only code (D3D12, Win32) can't be checked by the Linux build, so it needs its own compile database.

Decided

  • The fork's .clang-tidy, kept at 0 warnings. modernize-avoid-c-style-cast is on; modernize-use-auto is off (we write the type unless it's obvious).
  • Casts: static_cast/reinterpret_cast/const_cast/std::bit_cast; std::to_underlying(e) for enums. clang-tidy doesn't see extern "C" functions, macro arguments or disabled #if branches: those are watched by hand.
  • Windows-only code is checked on Linux with clang-cl compile databases generated by Tools/WindowsCompileDb/gen_windb.py (/std:c++23preview for clang-cl 23), run with -checks=-readability-duplicate-include.
  • CLion's shared settings live in .idea/ (profile, the "Primal sources" scope, the project dictionary); the rest of .idea/ is ignored.

Read first

  • Preferences, "Functions and calls", "Formatting, lint and warnings", "CLion inspections".
  • LinuxVulkanPort, "Tooling: .clang-format / .clang-tidy".

Steps

  • 1. Add .clang-tidy and run it over Engine/ on Linux. Read the first 20 findings before fixing any, to see what kinds there are.
  • 2. Fix the findings, C-style casts first. Commit the mechanical part separately and add it to .git-blame-ignore-revs.
  • 3. Set up Tools/WindowsCompileDb/ (the fork's README explains the Windows SDK and MSVC headers it needs) and run clang-tidy over the D3D12 and Win32 files.
  • 4. Add the shared .idea/ files and the .gitignore rule that tracks only those.
  • 5. Add a tidy step to a script you can run before every push (CI runs it from S0-07).

Done when

  • clang-tidy reports 0 warnings on the Linux database and on the Windows databases.
  • No C-style casts are left in Engine/, EngineTest/, EngineDLL/ or ContentTools/.

Claude can help with

  • Sorting a large batch of findings into "mechanical" and "needs a decision".
  • Generating the Windows compile databases and explaining false positives.

Learn

  • What a compile database is and why clang-tidy needs one.
  • The difference between static_cast and reinterpret_cast, and when std::bit_cast is the right one.
## Why Lint at zero from the start costs a little every day; lint turned on later cost the fork a repo-wide cast pass and a long tail of fixes. Windows-only code (D3D12, Win32) can't be checked by the Linux build, so it needs its own compile database. ## Decided - The fork's `.clang-tidy`, kept at 0 warnings. `modernize-avoid-c-style-cast` is on; `modernize-use-auto` is off (we write the type unless it's obvious). - Casts: `static_cast`/`reinterpret_cast`/`const_cast`/`std::bit_cast`; `std::to_underlying(e)` for enums. clang-tidy doesn't see `extern "C"` functions, macro arguments or disabled `#if` branches: those are watched by hand. - Windows-only code is checked on Linux with clang-cl compile databases generated by `Tools/WindowsCompileDb/gen_windb.py` (`/std:c++23preview` for clang-cl 23), run with `-checks=-readability-duplicate-include`. - CLion's shared settings live in `.idea/` (profile, the "Primal sources" scope, the project dictionary); the rest of `.idea/` is ignored. ## Read first - [Preferences](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Preferences), "Functions and calls", "Formatting, lint and warnings", "CLion inspections". - [LinuxVulkanPort](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/LinuxVulkanPort), "Tooling: `.clang-format` / `.clang-tidy`". ## Steps - [x] 1. Add `.clang-tidy` and run it over `Engine/` on Linux. Read the first 20 findings before fixing any, to see what kinds there are. - [x] 2. Fix the findings, C-style casts first. Commit the mechanical part separately and add it to `.git-blame-ignore-revs`. - [x] 3. Set up `Tools/WindowsCompileDb/` (the fork's README explains the Windows SDK and MSVC headers it needs) and run clang-tidy over the D3D12 and Win32 files. - [x] 4. Add the shared `.idea/` files and the `.gitignore` rule that tracks only those. - [x] 5. Add a `tidy` step to a script you can run before every push (CI runs it from S0-07). ## Done when - [x] clang-tidy reports 0 warnings on the Linux database and on the Windows databases. - [x] No C-style casts are left in `Engine/`, `EngineTest/`, `EngineDLL/` or `ContentTools/`. ## Claude can help with - Sorting a large batch of findings into "mechanical" and "needs a decision". - Generating the Windows compile databases and explaining false positives. ## Learn - What a compile database is and why clang-tidy needs one. - The difference between `static_cast` and `reinterpret_cast`, and when `std::bit_cast` is the right one.
Sign in to join this conversation.
No description provided.