This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] cppcoreguidelines-avoid-do-while: a new check
Needs ReviewPublic

Authored by DNS320 on May 16 2021, 4:56 AM.

Details

Summary

This simple check flags do-while statements according to rule ES.75 of the C++ Core Guidelines.

Diff Detail

Event Timeline

DNS320 created this revision.May 16 2021, 4:56 AM
DNS320 requested review of this revision.May 16 2021, 4:56 AM
Eugene.Zelenko added inline comments.
clang-tools-extra/docs/ReleaseNotes.rst
114

Please highlight do-while with double back-ticks.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-do-while.rst
7

Please highlight do-while with double back-ticks.

9

Please highlight do-while and while with double back-ticks.

This is going to be very noisey for codebases that use a do...while macro:

#define MACRO() do { Something(); With(); Multiple(); Statements(); } while (false)

Maybe you should ignore do statements that are in macro expansions as well as potentially do statements with a false condition.

DNS320 updated this revision to Diff 346360.May 19 2021, 2:03 AM

I updated the check according to the last review.

It ignores now do-while statements which are inside a macro and have a false condition. (false condition part was taken from bugprone-terminating-continue)

Tests were added and the check documentation has now a hint about ignoring do-while statements in macros.

DNS320 marked 3 inline comments as done.May 19 2021, 2:04 AM

Friendly Ping.

MTC added a subscriber: MTC.Aug 16 2021, 6:46 PM