[PATCH] D52695: [clang][Parse] Diagnose useless null statements (PR39111)

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 29 10:44:56 PDT 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: rsmith, aaron.ballman, efriedma.

clang has `-Wextra-semi` (https://reviews.llvm.org/D43162), which is not dictated by the currently selected standard.
While that is great, there is at least one more source of need-less semis - 'null statements'.
Sometimes, they are needed:

  for(int x = 0; continueToDoWork(x); x++)
    ; // Ugly code, but the semi is needed here.

But sometimes they are just there for no reason:

  switch(X) {
  case 0:
    return -2345;
  case 5:
    return 0;
  default:
    return 42;
  }; // <- oops
  
  ;;;;;;;;;;; <- OOOOPS, still not diagnosed. Clearly this is junk.

As usual, things may or may not go sideways in the presence of macros.
While evaluating this diag on my codebase of interest, it was unsurprisingly
discovered that Google Test macros are *very* prone to this.
And it seems many issues are deep within the GTest itself, not
in the snippets passed from the codebase that uses GTest.

So after some thought, i decided not do issue a diagnostic if the semi
is within *any* macro, be it either from the normal header, or system header.

Fixes PR39111 <https://bugs.llvm.org/show_bug.cgi?id=39111>


Repository:
  rC Clang

https://reviews.llvm.org/D52695

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  lib/Parse/ParseStmt.cpp
  test/Parser/extra-semi-resulting-in-nullstmt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52695.167614.patch
Type: text/x-patch
Size: 5379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180929/022eff46/attachment-0001.bin>


More information about the cfe-commits mailing list