Page MenuHomePhabricator

[clang-format] Top-level unwrapped lines don't follow a left brace
ClosedPublic

Authored by owenpan on Tue, Sep 14, 3:00 AM.

Details

Summary

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 Timeline

owenpan requested review of this revision.Tue, Sep 14, 3:00 AM
owenpan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptTue, Sep 14, 3:00 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

If there are no new tests, what went wrong before? Said invalid code?

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.

MyDeveloperDay accepted this revision.Wed, Sep 15, 6:39 AM

I guess this will prevent member functions in classes being treated as K&R functions right? if thats the case them this LGTM

This revision is now accepted and ready to land.Wed, Sep 15, 6:39 AM

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;
}