[llvm-bugs] [Bug 37454] New: [clang-format/ObjC] ObjC selector with C++ keyword causes incorrect formatting in subsequent code

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 14 09:42:02 PDT 2018


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

            Bug ID: 37454
           Summary: [clang-format/ObjC] ObjC selector with C++ keyword
                    causes incorrect formatting in subsequent code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bhamiltoncx at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

The C++ keyword `class` in an ObjC selector name causes subsequent code to be
mis-formatted.

Minimal repro:

% cat /tmp/foo.m
- (void)class:(id)clazz { }

// This should not be indented.
- (void)foo { }

% ./bin/clang-format -style google -debug /tmp/foo.m
Args: ./bin/clang-format -style google -debug /tmp/foo.m
File encoding: UTF8
Language: Objective-C
----
Line(0, FSC=0): minus[T=68, OC=0] l_paren[T=68, OC=2] void[T=68, OC=3]
r_paren[T=68, OC=7] class[T=68, OC=8] colon[T=68, OC=13] l_paren[T=68, OC=14]
identifier[T=68, OC=15] r_paren[T=68, OC=17] identifier[T=68, OC=18]
l_brace[T=68, OC=24]
Line(0, FSC=0): r_brace[T=68, OC=26] comment[T=68, OC=0] minus[T=68, OC=0]
l_paren[T=68, OC=2] void[T=68, OC=3] r_paren[T=68, OC=7] identifier[T=68, OC=8]
l_brace[T=21, OC=12]
Line(0, FSC=0): r_brace[T=68, OC=14]
Line(0, FSC=0): eof[T=68, OC=0]
Run 0...
AnnotatedTokens(L=0):
 M=0 C=0 T=ObjCMethodSpecifier S=1 B=0 BK=0 P=0 Name=minus L=1 PPK=2
FakeLParens= FakeRParens=0 II=0x0 Text='-'
 M=0 C=1 T=Unknown S=1 B=0 BK=0 P=33 Name=l_paren L=3 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=void L=7 PPK=2 FakeLParens=
FakeRParens=0 II=0x5627ed7f32a0 Text='void'
 M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=8 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=SelectorName S=0 B=0 BK=0 P=120 Name=class L=13 PPK=2 FakeLParens=
FakeRParens=0 II=0x5627ed7f3660 Text='class'
 M=0 C=0 T=ObjCMethodExpr S=0 B=0 BK=0 P=5020 Name=colon L=14 PPK=2
FakeLParens= FakeRParens=0 II=0x0 Text=':'
 M=0 C=1 T=Unknown S=0 B=0 BK=0 P=70 Name=l_paren L=15 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=identifier L=17 PPK=2 FakeLParens=
FakeRParens=0 II=0x5627ed7f7630 Text='id'
 M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=18 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=TrailingAnnotation S=0 B=0 BK=0 P=120 Name=identifier L=23 PPK=2
FakeLParens= FakeRParens=0 II=0x5627ed7f7660 Text='clazz'
 M=0 C=0 T=Unknown S=1 B=0 BK=1 P=23 Name=l_brace L=25 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='{'
----
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 B=0 BK=1 P=0 Name=r_brace L=1 PPK=2 FakeLParens=13/
FakeRParens=0 II=0x0 Text='}'
 M=1 C=1 T=LineComment S=2 B=0 BK=0 P=23 Name=comment L=101 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='// This should not be indented.'
 M=1 C=1 T=BinaryOperator S=1 B=0 BK=0 P=1020 Name=minus L=201 PPK=2
FakeLParens= FakeRParens=0 II=0x0 Text='-'
 M=0 C=1 T=Unknown S=1 B=0 BK=0 P=33 Name=l_paren L=203 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=140 Name=void L=207 PPK=2 FakeLParens=
FakeRParens=0 II=0x5627ed7f32a0 Text='void'
 M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=208 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=TrailingAnnotation S=0 B=0 BK=0 P=120 Name=identifier L=211 PPK=2
FakeLParens= FakeRParens=0 II=0x5627ed7f7690 Text='foo'
 M=0 C=0 T=FunctionLBrace S=1 B=0 BK=1 P=23 Name=l_brace L=213 PPK=2
FakeLParens= FakeRParens=0 II=0x0 Text='{'
----
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 B=0 BK=1 P=0 Name=r_brace L=1 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='}'
----
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=eof L=0 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=''
----
Breaking protruding token at column 4.
  Line: 0 (Reflow: 0)

---
Penalty for line: 1058
Breaking protruding token at column 4.
  Line: 0 (Reflow: 0)
Breaking protruding token at column 4.
  Line: 0 (Reflow: 0)
State: F|0|0|0 F|4|0|0 // This should not be indented.
Penalty for placing comment: 38
State: F|0|0|0 F|4|0|4 -
Penalty for placing minus: 1020
State: F|0|0|0 F|4|4|6 (
State: F|0|0|0 F|4|6|6 (|10|6|6 void
State: F|0|0|0 F|4|6|6 (|7|6|6 )
State: F|0|0|0 F|4|6|6 foo
State: F|0|0|0 F|4|6|6 {
Total number of analyzed states: 10
---
Replacements for run 0:
/tmp/foo.m: 25:+1:"
"
/tmp/foo.m: 27:+2:"

    "
/tmp/foo.m: 60:+1:"
    "
/tmp/foo.m: 74:+1:"
"
- (void)class:(id)clazz {
}   

    // This should not be indented.
    - (void)foo {
}

-- 
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/20180514/5bf260c6/attachment.html>


More information about the llvm-bugs mailing list