[llvm-bugs] [Bug 35319] New: Warn on semicolons immediately following "else"

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 15 10:57:30 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35319

            Bug ID: 35319
           Summary: Warn on semicolons immediately following "else"
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: brettw at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171115/5ec56300/attachment.html>


More information about the llvm-bugs mailing list