[PATCH] D51294: Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 28 02:48:10 PDT 2018


sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks!



================
Comment at: lib/Format/UnwrappedLineFormatter.cpp:486
       return 0;
+    if (Line.First->is(tok::kw_default)) {
+      const FormatToken *Tok = Line.First->getNextNonComment();
----------------
Just to check my understanding...
we want to treat `default` the same as `case`, but the heuristics are different:
 - `case` should only appear in a switch (but might be followed by a complex expression)
 - `default` has lots of meanings (but we can disambiguate: check if it's followed by a colon)

You could consider `// default: in switch statement` above this line.


================
Comment at: unittests/Format/FormatTest.cpp:1012
+                   "{\n"
+                   "case 0: {\n"
+                   "  return false;\n"
----------------
the intent of this test might be clearer if the cases were formatted as `case 0: { return false; }` on one line


Repository:
  rC Clang

https://reviews.llvm.org/D51294





More information about the cfe-commits mailing list