Before:
auto[a, b] = f();
After:
auto [a, b] = f();
or, if SpacesInSquareBrackets is true:
auto [ a, b ] = f();
Paths
| Differential D37132
[clang-format] Add support for C++17 structured bindings. ClosedPublic Authored by curdeius on Aug 25 2017, 1:08 AM.
Details Summary Before: auto[a, b] = f(); After: auto [a, b] = f(); or, if SpacesInSquareBrackets is true: auto [ a, b ] = f();
Diff Detail
Event TimelineComment Actions Are you changing the line endings here? Phabricator tells me that basically all the lines change. If so, please don't ;).
This revision is now accepted and ready to land.Sep 7 2017, 6:42 AM Comment Actions Thanks for this change. 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&& [..." Comment Actions Please review https://reviews.llvm.org/D35743.
Revision Contents
Diff 113077 lib/Format/FormatToken.h
lib/Format/TokenAnnotator.cppunittests/Format/FormatTest.cpp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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); }