This patch makes characterizing top-level unwrapped lines more precise. There are no test cases to add unless we want to include invalid ones, e.g.:
{ int f(i) int i; { return i + 1; } }
Differential D109752
[clang-format] Top-level unwrapped lines don't follow a left brace owenpan on Sep 14 2021, 3:00 AM. Authored by
Details This patch makes characterizing top-level unwrapped lines more precise. There are no test cases to add unless we want to include invalid ones, e.g.: { int f(i) int i; { return i + 1; } }
Diff Detail
Event TimelineComment Actions Yes, the said invalid code may get reformatted. However, the main purpose of this patch is to fix the efficiency issue as nested function declarators would no longer be checked for possible K&R C function definitions. Comment Actions I guess this will prevent member functions in classes being treated as K&R functions right? if thats the case them this LGTM Comment Actions It will prevent them from even being checked in parseStructuralElement as IsTopLevel is now false: case tok::l_paren: { parseParens(); // Break the unwrapped line if a K&R C function definition has a parameter // declaration. if (!IsTopLevel || !Style.isCpp() || !Previous || FormatTok->is(tok::eof)) break; const unsigned Position = Tokens->getPosition() + 1; assert(Position < AllTokens.size()); if (isC78ParameterDecl(FormatTok, AllTokens[Position], Previous)) { addUnwrappedLine(); return; } break; } |