Skip to content

Make modm compileable with Clang for tooling support#1349

Draft
chris-durand wants to merge 7 commits intomodm-io:developfrom
chris-durand:clang-tooling-support
Draft

Make modm compileable with Clang for tooling support#1349
chris-durand wants to merge 7 commits intomodm-io:developfrom
chris-durand:clang-tooling-support

Conversation

@chris-durand
Copy link
Copy Markdown
Member

@chris-durand chris-durand commented Apr 19, 2026

Enable modm to be compiled with Clang >= 22 to allow for use of Clang based tooling (e.g. Clang Tidy) in user projects.

Required changes:

  • Fix ill-formed code accepted by gcc (mostly missing typename, template keywords)
  • Remove broken circular dependencies in modm:ui:color that compile with GCC but not Clang
  • Implement constexpr versions of std::round, std::floor and std::ceil as clang still lacks constexpr support for more complex math functions
  • Handle minor differences in permitted attribute syntax
  • Correctly manage int32_t == int on Cortex-M with Clang instead of int32_t == long with GCC
  • Remove implementation of __atomic_is_lock_free for Clang (If Clang was to be used for compiling binaries to run on devices the atomic implementation would need changes)

Further changes:

  • Deprecate functionality in ArithmeticTraits available in the standard library
  • Deprecate modm::aligned_storage_t since std::aligned_storage is deprecated in C++23. Also remove all internal uses.

TODO:

  • Build hosted unit tests with Clang
  • Add clang-tidy support to the build system

Clang doesn't provide constexpr built-ins for round, ceil and floor yet.
GCC and libstd++ had support for constexpr std::round, std::ceil and
std::floor before the feature had been added to C++23.
Rgb, Rgb565, Hsv and Brightness types all circularly depended on each
other. The code is ill-formed, but compiled with gcc because of its
non-conforming way of instantiating templates. Especially, the code
doesn't compile with Clang.

All of those classes implemented converting constructors to convert
between each other. The dependency circle is broken up by replacing
some of those constructors with conversion operators in the other
type.

Furthermore, conversions between types of different bit widths were
disallowed where they were syntactically possible but yielded nonsensical
results. In those cases conversion to a smaller type resulted in bitwise
truncation. Conversion to a bigger type was done by simple assignment
without scaling.

TODO:
- strongly consider removing error-prone implicit conversions
- validate math for correctness
Functionality is provided by the standard library (std::numeric_limits,
std::make_signed_t, std::make_unsigned_t)
The alignment was erroneously 1 instead of 2
Deprecate modm::aligned_storage_t which relies on the deprecated type
std::aligned_storage. Remove all usages from modm and replace
them with a properly aligned std::byte array as recommended by C++ paper
P1413R3.
@chris-durand chris-durand force-pushed the clang-tooling-support branch from e3e9e4e to c650a4d Compare April 20, 2026 13:39
@chris-durand chris-durand requested a review from salkinium April 24, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant