Index: lib/Format/UnwrappedLineParser.h =================================================================== --- lib/Format/UnwrappedLineParser.h +++ lib/Format/UnwrappedLineParser.h @@ -116,6 +116,7 @@ // parses the record as a child block, i.e. if the class declaration is an // expression. void parseRecord(bool ParseAsExpr = false); + void parseObjCLightweightGenericList(); void parseObjCProtocolList(); void parseObjCUntilAtEnd(); void parseObjCInterfaceOrImplementation(); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -2120,6 +2120,26 @@ // "} n, m;" will end up in one unwrapped line. } +void UnwrappedLineParser::parseObjCLightweightGenericList() { + assert(FormatTok->Tok.is(tok::less) && "'<' expected."); + // Unlike protocol lists, generic parameterizations support + // nested angles: + // + // @interface Foo> : + // NSObject + // + // so we need to count how many open angles we have left. + unsigned NumOpenAngles = 1; + do { + nextToken(); + if (FormatTok->Tok.is(tok::less)) + NumOpenAngles++; + else if (FormatTok->Tok.is(tok::greater)) + NumOpenAngles--; + } while (!eof() && NumOpenAngles != 0); + nextToken(); // Skip '>'. +} + void UnwrappedLineParser::parseObjCProtocolList() { assert(FormatTok->Tok.is(tok::less) && "'<' expected."); do @@ -2155,7 +2175,11 @@ nextToken(); nextToken(); // interface name - // @interface can be followed by either a base class, or a category. + // @interface can be followed by a lightweight generic + // specialization list, then either a base class or a category. + if (FormatTok->Tok.is(tok::less)) + parseObjCLightweightGenericList(); + if (FormatTok->Tok.is(tok::colon)) { nextToken(); nextToken(); // base class name Index: unittests/Format/FormatTestObjC.cpp =================================================================== --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -298,6 +298,18 @@ "+ (id)init;\n" "@end"); + verifyFormat("@interface Foo : Bar {\n" + " int _i;\n" + "}\n" + "+ (id)init;\n" + "@end"); + + verifyFormat("@interface Foo > : Xyzzy {\n" + " int _i;\n" + "}\n" + "+ (id)init;\n" + "@end"); + verifyFormat("@interface Foo (HackStuff) {\n" " int _i;\n" "}\n"