[cfe-commits] r172718 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Thu Jan 17 05:31:52 PST 2013


Author: djasper
Date: Thu Jan 17 07:31:52 2013
New Revision: 172718

URL: http://llvm.org/viewvc/llvm-project?rev=172718&view=rev
Log:
Allow breaking after the trailing const after a function declaration.

Before:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY(
    aaaaaaaaaaaaa);

After:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const
    GUARDED_BY(aaaaaaaaaaaaa);

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172718&r1=172717&r2=172718&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 17 07:31:52 2013
@@ -1390,6 +1390,13 @@
       // change the "binding" behavior of a comment.
       return false;
 
+    // Allow breaking after a trailing 'const', e.g. after a method declaration,
+    // unless it is follow by ';', '{' or '='.
+    if (Left.is(tok::kw_const) && Left.Parent != NULL &&
+        Left.Parent->is(tok::r_paren))
+      return Right.isNot(tok::l_brace) && Right.isNot(tok::semi) &&
+             Right.isNot(tok::equal);
+
     // We only break before r_brace if there was a corresponding break before
     // the l_brace, which is tracked by BreakBeforeClosingBrace.
     if (Right.is(tok::r_brace))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172718&r1=172717&r2=172718&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 17 07:31:52 2013
@@ -899,6 +899,10 @@
 TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
   verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
                "    GUARDED_BY(aaaaaaaaaaaaa);");
+  verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
+               "    GUARDED_BY(aaaaaaaaaaaaa);");
+  verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
+               "    GUARDED_BY(aaaaaaaaaaaaa) {}");
 }
 
 TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {





More information about the cfe-commits mailing list