]> granicus.if.org Git - clang/commit
[clang-format] Support lightweight Objective-C generics
authorBen Hamilton <benhamilton@google.com>
Thu, 5 Apr 2018 15:26:25 +0000 (15:26 +0000)
committerBen Hamilton <benhamilton@google.com>
Thu, 5 Apr 2018 15:26:25 +0000 (15:26 +0000)
commit47f00f84747052f94f483b40ec492c3804c907b1
treee31b502caf19e93223ebf4a078a786fb2bd7f3e8
parent218db8fb83971ccccfbb33d998a56d3cf0c977e1
[clang-format] Support lightweight Objective-C generics

Summary:
Previously, `clang-format` didn't understand lightweight
Objective-C generics, which have the form:

```
@interface Foo <KeyType,
                ValueTypeWithConstraint : Foo,
AnotherValueTypeWithGenericConstraint: Bar<Baz>, ... > ...
```

The lightweight generic specifier list appears before the base
class, if present, but because it starts with < like the protocol
specifier list, `UnwrappedLineParser` was getting confused and
failed to parse interfaces with both generics and protocol lists:

```
@interface Foo <KeyType> : NSObject <NSCopying>
```

Since the parsed line would be incomplete, the format result
would be very confused (e.g., https://bugs.llvm.org/show_bug.cgi?id=24381).

This fixes the issue by explicitly parsing the ObjC lightweight
generic conformance list, so the line is fully parsed.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=24381
Test Plan: New tests added. Ran tests with:
  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D45185

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329298 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestObjC.cpp