This is an archive of the discontinued LLVM Phabricator instance.

clang: Tweak behaviour of warn_empty_while_body and warn_empty_if_body
ClosedPublic

Authored by bmoody on Jun 22 2022, 8:55 PM.

Details

Summary

Use the if/while statement right paren location instead of the end of the
condition expression to determine if the semicolon is on its own line, for the
purpose of not warning about code like this:

while (foo())
  ;

Using the condition location meant that we would also not report a warning on
code like this:

while (MACRO(a,
             b));
  body();

The right paren loc wasn't stored in the AST or passed into Sema::ActOnIfStmt
when this logic was first written.

Diff Detail

Event Timeline

bmoody created this revision.Jun 22 2022, 8:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2022, 8:55 PM
bmoody requested review of this revision.Jun 22 2022, 8:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2022, 8:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk accepted this revision.Jun 23 2022, 12:08 PM

lgtm

Test cases look good, thanks!

This revision is now accepted and ready to land.Jun 23 2022, 12:08 PM

I don't have merge access so please merge on my behalf :) Thanks!

gribozavr2 accepted this revision.Jun 23 2022, 5:21 PM
This revision was landed with ongoing or failed builds.Jun 23 2022, 5:40 PM
This revision was automatically updated to reflect the committed changes.