[PATCH] D148484: [clang-format] Correctly format goto labels followed by blocks

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 02:27:17 PDT 2023


HazardyKnusperkeks added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:714
     // are in a control flow statements as well as several style flags.
-    if (Line.First->is(tok::kw_case) ||
+    if (Line.First->is(tok::kw_case) || Line.Last->is(TT_GotoLabelColon) ||
+        Line.Last->endsSequence(tok::l_brace, TT_GotoLabelColon) ||
----------------
sstwcw wrote:
> Should I make this change?
> 
> Without it:
> 
> ```
> label: { break; }
> ```
> 
> With it:
> 
> ```
> label: {
>   break;
> }
> ```
> 
> Without the entire patch:
> 
> ```
> label : { break; }
> ```
I'd say no. To not change this (too much).


================
Comment at: clang/unittests/Format/FormatTest.cpp:3020-3024
   verifyFormat("{\n"
                "  some_code();\n"
-               "test_label:;\n"
-               "  int i = 0;\n"
-               "}");
----------------
Why did you remove that?


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1711
 
+
 TEST_F(TokenAnnotatorTest, UnderstandsConditionParens) {
----------------
remove


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148484/new/

https://reviews.llvm.org/D148484



More information about the cfe-commits mailing list