From 5d393210ed7c1af6fd010829a136093d06251915 Mon Sep 17 00:00:00 2001
From: Daniel Jasper <djasper@google.com>
Date: Mon, 8 Dec 2014 21:28:31 +0000
Subject: [PATCH] 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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223694 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/ContinuationIndenter.cpp | 3 ++-
 unittests/Format/FormatTestJava.cpp | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index 8538f9a460..5f55e0daa0 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -766,7 +766,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
     //       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 <=
diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp
index 91b38ad758..6f7e43f325 100644
--- a/unittests/Format/FormatTestJava.cpp
+++ b/unittests/Format/FormatTestJava.cpp
@@ -373,6 +373,11 @@ TEST_F(FormatTestJava, NeverAlignAfterReturn) {
                "    .bbbbbbbbbbbbbbbbbbb()\n"
                "    .ccccccccccccccccccc();",
                getStyleWithColumns(40));
+  verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n"
+               "    .bbbbbbbbbbbbbbbbbbb(\n"
+               "         ccccccccccccccc)\n"
+               "    .ccccccccccccccccccc();",
+               getStyleWithColumns(40));
 }
 
 TEST_F(FormatTestJava, FormatsInnerBlocks) {
-- 
2.40.0