Page MenuHomePhabricator

[clang-format] Add support for C++17 structured bindings.
ClosedPublic

Authored by curdeius on Aug 25 2017, 1:08 AM.

Details

Event Timeline

curdeius created this revision.Aug 25 2017, 1:08 AM
djasper edited edge metadata.Aug 29 2017, 5:10 AM

Are you changing the line endings here? Phabricator tells me that basically all the lines change. If so, please don't ;).

lib/Format/TokenAnnotator.cpp
345

I'd prefer to move this into a separate function or a lambda, i.e.:

bool isCppStructuredBinding(const FormatToken *Tok) {
  if (!Style.isCpp() || !Tok->is(tok::l_square))
    return false;
  while (Tok && Tok->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp, tok::ampamp))
    Tok = Tok->getPreviousNonComment()) {
  return Tok && Tok->is(tok::kw_auto);
}
curdeius updated this revision to Diff 113073.Aug 29 2017, 5:52 AM

Fix line endings.

curdeius updated this revision to Diff 113076.Aug 29 2017, 6:15 AM

Revert unintended format changes.

curdeius updated this revision to Diff 113077.Aug 29 2017, 6:17 AM

Fix line endings again.

curdeius updated this revision to Diff 113079.Aug 29 2017, 6:25 AM

Extract method.

curdeius updated this revision to Diff 113084.Aug 29 2017, 6:43 AM

Fix: use do-while loop.

djasper accepted this revision.Sep 7 2017, 6:42 AM

Looks good. Sorry for the delay.

This revision is now accepted and ready to land.Sep 7 2017, 6:42 AM
curdeius closed this revision.Sep 7 2017, 7:29 AM
chh added a subscriber: chh.Sep 15 2017, 2:35 PM

Thanks for this change.
Could you take a look of https://reviews.llvm.org/D35743 too?

This outputs a space before and after "&" or "&&", like this

"auto & [...",  "auto && [..."

Could we remove one of the space to a format like the following?

"auto& [...",  "auto&& [..."
chh added a comment.Sep 18 2017, 4:02 PM

Please review https://reviews.llvm.org/D35743.
I uploaded there a new diff that should fix the spaces around & and && tokens.
Thanks.