Skip to content

Comments

Fix implicit integer conversion warnings with clang-21#33

Merged
mattgodbolt merged 1 commit intomainfrom
fix-clang21
Nov 3, 2025
Merged

Fix implicit integer conversion warnings with clang-21#33
mattgodbolt merged 1 commit intomainfrom
fix-clang21

Conversation

@mattgodbolt
Copy link
Owner

Summary

  • Fixes implicit integer conversion warnings when building with clang-21.1.0
  • Adds explicit static_cast for bitwise NOT operations on uint8_t and uint16_t
  • All tests pass with clang-21.1.0

Details

Clang-21 is stricter about implicit integer conversions than clang-20. The bitwise NOT operator (~) on uint8_t/uint16_t promotes to int due to C++ integer promotion rules, requiring explicit casts back to the smaller types.

Changes

Fixed in 4 locations:

  • Flags::operator~(): Added static_cast<std::uint8_t>
  • Alu::sub8(): Added static_cast<std::uint8_t> for ~rhs
  • Alu::sub16(): Added static_cast<std::uint16_t> for ~rhs
  • Alu::sbc16(): Added static_cast<std::uint16_t> for ~rhs

Test plan

  • Build succeeds with clang-21.1.0 and modules disabled
  • All 6 test suites pass (peripheral, z80 v1/v2/v3, common)
  • Pre-commit hooks pass

🤖 Generated with Claude Code

Clang-21 is stricter about implicit integer conversions than clang-20.
The bitwise NOT operator (~) on uint8_t/uint16_t promotes to int, requiring
explicit casts back to the smaller types.

Fixed in 4 locations:
- Flags::operator~(): Added static_cast<std::uint8_t>
- Alu::sub8(): Added static_cast<std::uint8_t> for ~rhs
- Alu::sub16(): Added static_cast<std::uint16_t> for ~rhs
- Alu::sbc16(): Added static_cast<std::uint16_t> for ~rhs

All tests pass with clang-21.1.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@mattgodbolt
Copy link
Owner Author

Despite the failing build (cc @hanickadot ) - I am going to merge this as it fixes some clang issues on Linux too.

@mattgodbolt mattgodbolt merged commit 6d06031 into main Nov 3, 2025
6 of 10 checks passed
@mattgodbolt mattgodbolt deleted the fix-clang21 branch November 3, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant