[PATCH] D133571: [clang-format] Introduce NoFallThrough option into AllowShortCaseLabelsOnASingleLine

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 9 05:39:44 PDT 2022


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, owenpan, curdeius.
MyDeveloperDay added a project: clang-format.
Herald added a project: All.
MyDeveloperDay requested review of this revision.
Herald added a project: clang.

As highlighted by https://github.com/llvm/llvm-project/issues/57609

Give more control when using the AllowShortCaseLabelsOnASingleLine to not put fallthrough code onto the same line

  switch (i) {
  case 0: g(); [[fallthrough]];
  case 1: f(); break;
  }

whether that fallthrough is marked with the attribute or implicit

  switch (i) {
  case 0:
  case 1: return i;
  case 2:
  case 3: i *= 2; break;
  }

in these cases don't make them short

  switch (i) {
  case 0:
    g();
    [[fallthrough]];
  case 1:
    f();
    break;
  }



  switch (i) {
  case 0:
  case 1:
    return i;
  case 2:
  case 3:
    i *= 2;
    break;
  }

Fixes: 57609


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133571

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133571.459020.patch
Type: text/x-patch
Size: 13147 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220909/c0b84f7c/attachment-0001.bin>


More information about the cfe-commits mailing list