diff options
author | Daniel Jasper <djasper@google.com> | 2014-03-21 12:38:57 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-03-21 12:38:57 +0000 |
commit | a125d53a7b35cff606b9250feeb64e9761a3a308 (patch) | |
tree | c704cbc06b13707e4035d3bdbbbcc77ad1059e22 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 28df0a356ecb36da8b234783561a4c2fdbd0232a (diff) | |
download | bcm5719-llvm-a125d53a7b35cff606b9250feeb64e9761a3a308.tar.gz bcm5719-llvm-a125d53a7b35cff606b9250feeb64e9761a3a308.zip |
clang-format: Let a trailing comma in braced lists enforce linebreaks.
Before:
vector<int> x{1, 2, 3, 4, };
After:
vector<int> x{
1, 2, 3, 4,
};
This fixes llvm.org/PR18519.
llvm-svn: 204458
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c3cc000044b..efb983e7366 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1478,6 +1478,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { + const FormatToken &Left = *Right.Previous; if (Right.is(tok::comment)) { return Right.Previous->BlockKind != BK_BracedInit && Right.Previous->Type != TT_CtorInitializerColon && @@ -1514,6 +1515,13 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, Style.Language == FormatStyle::LK_Proto) { // Don't enums onto single lines in protocol buffers. return true; + } else if ((Left.is(tok::l_brace) && Left.MatchingParen && + Left.MatchingParen->Previous && + Left.MatchingParen->Previous->is(tok::comma)) || + (Right.is(tok::r_brace) && Left.is(tok::comma))) { + // If the last token before a '}' is a comma, the intention is to insert a + // line break after it in order to make shuffling around entries easier. + return true; } return false; } |