r186583 - clang-format: Fix bad line break with pointers to members.
Daniel Jasper
djasper at google.com
Thu Jul 18 07:46:07 PDT 2013
Author: djasper
Date: Thu Jul 18 09:46:07 2013
New Revision: 186583
URL: http://llvm.org/viewvc/llvm-project?rev=186583&view=rev
Log:
clang-format: Fix bad line break with pointers to members.
Before:
void f() {
(a->*
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(aaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
}
After:
void f() {
(a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
}
Also add missing test case.
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=186583&r1=186582&r2=186583&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jul 18 09:46:07 2013
@@ -1267,7 +1267,7 @@ bool TokenAnnotator::canBreakBefore(cons
Left.Previous->is(tok::kw___attribute))
return false;
if (Left.is(tok::l_paren) && (Left.Previous->Type == TT_BinaryOperator ||
- Left.Previous->is(tok::r_paren)))
+ Left.Previous->Type == TT_CastRParen))
return false;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186583&r1=186582&r2=186583&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jul 18 09:46:07 2013
@@ -3335,6 +3335,10 @@ TEST_F(FormatTest, UnderstandsPointersTo
" ((*a).*f)();\n"
" a.*x;\n"
"}");
+ verifyFormat("void f() {\n"
+ " (a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(\n"
+ " aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);\n"
+ "}");
FormatStyle Style = getLLVMStyle();
Style.PointerBindsToType = true;
verifyFormat("typedef bool* (Class::*Member)() const;", Style);
@@ -3633,6 +3637,11 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("my_int a = (my_int)++ a;");
verifyFormat("my_int a = (my_int) + 2;");
+ // Don't break after a cast's
+ verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
+ " (aaaaaaaaaaaaaaaaaaaaaaaaaa *)(aaaaaaaaaaaaaaaaaaaaaa +\n"
+ " bbbbbbbbbbbbbbbbbbbbbb);");
+
// These are not casts.
verifyFormat("void f(int *) {}");
verifyFormat("f(foo)->b;");
More information about the cfe-commits
mailing list