[PATCH] D89496: [Format/ObjC] Correctly handle base class with lightweight generics and protocol

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 15 14:10:41 PDT 2020


benhamilton created this revision.
benhamilton added reviewers: sammccall, MyDeveloperDay.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
benhamilton requested review of this revision.

ClangFormat does not correctly handle an Objective-C interface declaration
with both lightweight generics and a protocol conformance.

This simple example:

  @interface Foo : Bar <Baz> <Blech>
  
  @end

means `Foo` extends `Bar` (a lightweight generic class whose type
parameter is `Baz`) and also conforms to the protocol `Blech`.

ClangFormat should not apply any changes to the above example, but
instead it currently formats it quite poorly:

  @interface Foo : Bar <Baz>
  <Blech>
  
      @end
      

The bug is that `UnwrappedLineParser` assumes an open-angle bracket
after a base class name is a protocol list, but it can also be a
lightweight generic specification.

This diff fixes the bug by factoring out the logic to parse
lightweight generics so it can apply both to the declared class
as well as the base class.

Test Plan: New tests added. Ran tests with:

  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
  Confirmed tests failed before diff and passed after diff.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89496

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestObjC.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89496.298462.patch
Type: text/x-patch
Size: 4344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201015/4190210e/attachment.bin>


More information about the cfe-commits mailing list