Repeated parameter with side effects passed to macro


I have implemented a proof-of-concept clang-tidy checker for this CERT rule:

The checker seems to work. It warns if a macro argument has side effects and it is repeated in the macro. Currently it only warns for ++ and – but this can be improved.

The error message can probably be tweaked. Feel free to suggest a better message.

Is this approach looking good or should the checker be moved/redesigned?

Best Regards,

MacroRepeated.diff (11.5 KB)

Hi Anders,

I’ve just noticed your mail while searching something in my inbox. Normally the patches should go to the cfe-commits list, there they have fewer chances to come unnoticed. It would also be convenient if you sent clang-tidy patches using LLVM Phabricator (docs here: please specify myself as a reviewer and CC cfe-commits.