This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix regression about short functions after #else
ClosedPublic

Authored by krasimir on Sep 18 2017, 6:36 AM.

Details

Summary

This patch fixes a regression introduced in r312904, where the formatter confuses
the else in #else with an else of an if-else statement.
For example, formatting this code with google style

#ifdef A
int f() {}
#else
int f() {}
#endif

resulted in

#ifdef A
int f() {}
#else
int f() {
}
#endif

Diff Detail

Repository
rL LLVM

Event Timeline

krasimir created this revision.Sep 18 2017, 6:36 AM
krasimir edited reviewers, added: sammccall; removed: djasper, klimek.Oct 2 2017, 7:59 AM
sammccall accepted this revision.Oct 2 2017, 8:20 AM

This test looks like it was intended to catch some case, maybe we're now mishandling some case like

if (foo)
{
}
else
{
  // this can now be merged
}

But there's no testcase and I'm guessing, so let's fix the #else bug :-)

This revision is now accepted and ready to land.Oct 2 2017, 8:20 AM
This revision was automatically updated to reflect the committed changes.