LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 35319 - Warn on semicolons immediately following "else"
Summary: Warn on semicolons immediately following "else"
Status: REOPENED
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-15 10:57 PST by Brett Wilson
Modified: 2018-02-28 16:23 PST (History)
5 users (show)

See Also:
Fixed By Commit(s): r318456


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brett Wilson 2017-11-15 10:57:30 PST
clang version 6.0.0 (trunk 317263)

This code:

    int main(int argc, char** argv) {
      if (argc > 4);   // <-- Note semicolon!
      return 0;
    }

Gives:

    eraseme.cc:2:16: warning: if statement has empty body [-Wempty-body]
      if (argc > 4);
                   ^
    eraseme.cc:2:16: note: put the semicolon on a separate line to silence this
          warning
    1 warning generated.

This is good! And it also works for "else if" cases. But I just did the same bug and put a semicolon after a bare else:

    int main(int argc, char** argv) {
      if (argc > 4)
        return 1;
      else;  // <- Semicolon
        return 2;
      return 0;
    }

And there is no warning. This was pretty tricky to find and it seems like the same rule for "if" semicolons should just also be applied to "else".
Comment 1 Reid Kleckner 2017-11-16 13:32:37 PST
Thanks, should be fixed by r318456.
Comment 2 Reid Kleckner 2018-02-28 16:23:57 PST
This was reverted.