1

In particular, I'm using Qt; our codebase is still littered with old foreach macros, like foreach (T foo, bar) { ... }. I'd like to turn that to for (T foo : bar) { ... }. Is there a way to write a clang-tidy rule to do this?

Ben
  • 9,184
  • 1
  • 43
  • 56

1 Answers1

2

Yes, it's definitely possible. Clang-tidy is open source so nothing stops you from modifying the code or writing your own checks.

The modernize-loop-convert check does something very similar to your use case so it's possibly a good start. (source)

Clang-tidy even has official documentation on writing new checks.

pablo285
  • 2,460
  • 4
  • 14
  • 38
  • Thank you. I searched a bunch but didn't find it. I had hoped (and perhaps expected?) that it could be done with config files – something like regexps on the AST – so that assumption may have lead me in the wrong direction when searching. – Ben Sep 19 '19 at 11:56