This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add cppcoreguidelines-avoid-do-while check
ClosedPublic

Authored by carlosgalvezp on Aug 23 2022, 4:30 AM.

Diff Detail

Event Timeline

carlosgalvezp created this revision.Aug 23 2022, 4:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 4:30 AM
carlosgalvezp requested review of this revision.Aug 23 2022, 4:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 4:30 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Document default value

Add check to list of checks.

Eugene.Zelenko added inline comments.
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst
7

Please synchronize first statement with Release Notes. This check us usually omitted.

22

Links usually placed at the end.

42

Please use single back-ticks for options values.

carlosgalvezp marked 2 inline comments as done.

Address comments

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

I think having the link after the options would make it a bit disconnected. Instead I typically find Options at the very end, after the description.

See for example:
https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/owning-memory.html

WDYT?

PS: @aaron.ballman I didn't add you as reviewer since you have expressed in the past that you'd prefer not to review C++ Core Guidelines patches. Let me know if that has changed :)

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

Add a couple more tests.

The AllowWhileFlase option seems the wrong way to go about silencing do while(false) macros. Would it not make more sense to just ignore macros, or if you want more specificty don't warn on macros with a false condition?

The AllowWhileFlase option seems the wrong way to go about silencing do while(false) macros. Would it not make more sense to just ignore macros, or if you want more specificty don't warn on macros with a false condition?

Strictly speaking, the C++ Core Guidelines do not make any such exception for macros. That's why I thought an option would allow both users who want to comply strictly, and users who want a bit more flexibility (without having to NOLINT their way out of it). Similar options exist for other C++ Core Guidelines checks.

The AllowWhileFlase option seems the wrong way to go about silencing do while(false) macros. Would it not make more sense to just ignore macros, or if you want more specificty don't warn on macros with a false condition?

Strictly speaking, the C++ Core Guidelines do not make any such exception for macros. That's why I thought an option would allow both users who want to comply strictly, and users who want a bit more flexibility (without having to NOLINT their way out of it). Similar options exist for other C++ Core Guidelines checks.

Or do you mean renaming the AllowWhileFalse option to IgnoreMacros and make the exception broader? I'd be fine with that as well, I'm not particularly happy with the AllowWhileFalse name :)

Rename option to IgnoreMacros and update logic and tests.

@njames93 Is there anything else I should address?

@njames93 Friendly ping. The patch has addressed all comments and remained unchanged for 2 weeks. I would like to land it latest next week. If you are happy with the patch, please accept the review. Alternatively, please let me know if you intend to continue reviewing.

Adjust warning message for consistency.

@njames93 Friendly ping. The patch has addressed all comments and remained unchanged for 2 weeks. I would like to land it latest next week. If you are happy with the patch, please accept the review. Alternatively, please let me know if you intend to continue reviewing.

I do intend, but I'm currently between 2 jobs and accommodation atm, once life settles down next week, I should have more time.

@njames93 Friendly ping. The patch has addressed all comments and remained unchanged for 2 weeks. I would like to land it latest next week. If you are happy with the patch, please accept the review. Alternatively, please let me know if you intend to continue reviewing.

I do intend, but I'm currently between 2 jobs and accommodation atm, once life settles down next week, I should have more time.

Totally understandable, thanks for the response! Are there other reviewers that could review the patch instead, to remove some load off you?

bigdavedev accepted this revision.Oct 9 2022, 11:42 PM

LGTM. All comments addressed and the check world as intended.

This revision is now accepted and ready to land.Oct 9 2022, 11:42 PM