This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix bugprone-terminating-continue when continue appears inside a switch
ClosedPublic

Authored by njames93 on Mar 10 2021, 5:30 AM.

Details

Summary

Don't emit a warning if the continue appears in a switch context as changing it to break will break out of the switch rather than a do loop containing the switch.
Fixes https://llvm.org/PR49492.

Diff Detail

Event Timeline

njames93 created this revision.Mar 10 2021, 5:30 AM
njames93 requested review of this revision.Mar 10 2021, 5:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2021, 5:30 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
njames93 edited the summary of this revision. (Show Details)Mar 10 2021, 5:31 AM
aaron.ballman accepted this revision.Mar 18 2021, 1:10 PM

LGTM, but please commit with a better commit message.

clang-tools-extra/test/clang-tidy/checkers/bugprone-terminating-continue.cpp
81

I'd appreciate an additional test:

switch (2) {
case 2: do {
  continue; // Should still diagnose this one
} while (0);
}
This revision is now accepted and ready to land.Mar 18 2021, 1:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2021, 1:10 PM
njames93 edited the summary of this revision. (Show Details)Mar 18 2021, 3:50 PM
njames93 updated this revision to Diff 331713.Mar 18 2021, 3:51 PM
njames93 marked an inline comment as done.

Add test case for do inside switch.