Customising clang-tidy to modernise your legacy C++ code

Speaker: Mike Crowe

Audience level: [ Intermediate ]

Modernising your codebase sounds fun to start with, but quickly gets tedious. Can we use tools to help us speed through the tedious bit?

This is tale of how I've modernised over seven thousand individual lines of rather old C++ code by mostly-automatically moving its diagnostic logging from using wrappers for `printf` to libfmt's fmt::printf, then to fmt::print and hopefully on to C++23's std::print by using a small clang-tidy check based on the code behind Clang 17's modernize-use-std-print clang-tidy check.

We'll consider how the move to fmt::printf was easy and beneficial, why moving to fmt::print was rather harder and how that led me to write what became the modernize-use-std-print clang-tidy check and then adapt it for our use case. Having done that, I was able to re-use that work for more checks to modernise more of the code.

If you're thinking, "I'm no LLVM or Clang expert, so maybe this talk is not for me" - I'm not either! So I'll share some of the challenges I faced on the way to help you avoid them and get to the fun part faster.