r223694 - clang-format: Indent correctly in conditional expressions after return.

Daniel Jasper djasper at google.com
Mon Dec 8 13:28:31 PST 2014


Author: djasper
Date: Mon Dec  8 15:28:31 2014
New Revision: 223694

URL: http://llvm.org/viewvc/llvm-project?rev=223694&view=rev
Log:
clang-format: Indent correctly in conditional expressions after return.

This only applies when not aligning after the return itself (which is
commonly done for C++.

Before:
  return aaaaaaaaaa
      ? bbbbbbbbbb(
             bbbbbb)  // This is indented relative to aaaaaaaaaa.
      : b;

After:
  return aaaaaaaaaa
      ? bbbbbbbbbb(
            bbbbbb)
      : b;

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=223694&r1=223693&r2=223694&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Dec  8 15:28:31 2014
@@ -766,7 +766,8 @@ void ContinuationIndenter::moveStatePast
     //       ParameterToInnerFunction));
     if (*I > prec::Unknown)
       NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
-    NewParenState.StartOfFunctionCall = State.Column;
+    if (*I != prec::Conditional)
+      NewParenState.StartOfFunctionCall = State.Column;
 
     // Always indent conditional expressions. Never indent expression where
     // the 'operator' is ',', ';' or an assignment (i.e. *I <=

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=223694&r1=223693&r2=223694&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Mon Dec  8 15:28:31 2014
@@ -373,6 +373,11 @@ TEST_F(FormatTestJava, NeverAlignAfterRe
                "    .bbbbbbbbbbbbbbbbbbb()\n"
                "    .ccccccccccccccccccc();",
                getStyleWithColumns(40));
+  verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n"
+               "    .bbbbbbbbbbbbbbbbbbb(\n"
+               "         ccccccccccccccc)\n"
+               "    .ccccccccccccccccccc();",
+               getStyleWithColumns(40));
 }
 
 TEST_F(FormatTestJava, FormatsInnerBlocks) {





More information about the cfe-commits mailing list