This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix incorrect formatting of lambdas inside brace initialisation
ClosedPublic

Authored by curdeius on Jan 3 2022, 12:34 PM.

Details

Summary

Fixes https://github.com/llvm/llvm-project/issues/27146.
Fixes https://github.com/llvm/llvm-project/issues/52943.

Before:

namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr; }}, v);
}

} // namespace ns

int break_me() {
  int x = 42;
  return int{[x = x]() {
    return x;
  }()};
}

got formatted as:

namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr;
}
} // namespace ns
, v);
}

} // namespace ns

int break_me() {
  int x = 42;
  return int{[x = x](){return x;
}
()
}
;
}

Diff Detail

Unit TestsFailed

Event Timeline

curdeius requested review of this revision.Jan 3 2022, 12:34 PM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2022, 12:34 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
curdeius updated this revision to Diff 397123.Jan 3 2022, 12:41 PM

This patch fixes as well https://github.com/llvm/llvm-project/issues/27146.
Added a test case.

curdeius retitled this revision from [clang-format] Fix incorrect formatting of lambdas inside brace initialisation when the return type has square brackets `[]`. to [clang-format] Fix incorrect formatting of lambdas inside brace initialisation.Jan 3 2022, 12:42 PM
curdeius edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Jan 3 2022, 12:57 PM
HazardyKnusperkeks added a project: Restricted Project.Jan 3 2022, 12:58 PM
owenpan accepted this revision.Jan 3 2022, 1:56 PM
This revision was landed with ongoing or failed builds.Jan 3 2022, 11:28 PM
This revision was automatically updated to reflect the committed changes.