r294179 - clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and AlignAfterOpenBracket
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 6 02:55:49 PST 2017
Author: djasper
Date: Mon Feb 6 04:55:49 2017
New Revision: 294179
URL: http://llvm.org/viewvc/llvm-project?rev=294179&view=rev
Log:
clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and AlignAfterOpenBracket
Fix for the formatting options combination of
BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not
handling long templates correctly. This patch allows a break after an
opening left parenthesis, TemplateOpener, or bracket when both options
are enabled.
Patch by Daphne Pfister, thank you!
Fixes llvm.org/PR30304.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294179&r1=294178&r2=294179&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 6 04:55:49 2017
@@ -2635,7 +2635,8 @@ bool TokenAnnotator::canBreakBefore(cons
tok::colon, tok::l_square, tok::at) ||
(Left.is(tok::r_paren) &&
Right.isOneOf(tok::identifier, tok::kw_const)) ||
- (Left.is(tok::l_paren) && !Right.is(tok::r_paren));
+ (Left.is(tok::l_paren) && !Right.is(tok::r_paren)) ||
+ (Left.is(TT_TemplateOpener) && !Right.is(TT_TemplateCloser));
}
void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=294179&r1=294178&r2=294179&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 6 04:55:49 2017
@@ -6140,6 +6140,44 @@ TEST_F(FormatTest, WrapsTemplateDeclarat
"};");
}
+TEST_F(FormatTest, WrapsTemplateParameters) {
+ FormatStyle Style = getLLVMStyle();
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+ verifyFormat(
+ "template <typename... a> struct q {};\n"
+ "extern q<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>\n"
+ " y;",
+ Style);
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ verifyFormat(
+ "template <typename... a> struct r {};\n"
+ "extern r<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>\n"
+ " y;",
+ Style);
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+ verifyFormat(
+ "template <typename... a> struct s {};\n"
+ "extern s<\n"
+ " aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa>\n"
+ " y;",
+ Style);
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ verifyFormat(
+ "template <typename... a> struct t {};\n"
+ "extern t<\n"
+ " aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa>\n"
+ " y;",
+ Style);
+}
+
TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::\n"
More information about the cfe-commits
mailing list