<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - BreakBeforeBraces: Custom ignores BraceWrapping flags"
   href="https://llvm.org/bugs/show_bug.cgi?id=25073">25073</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>BreakBeforeBraces: Custom ignores BraceWrapping flags
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Formatter
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mattipee@yahoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang-format -version

clang-format version 3.8.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
fad8a5cf2c6fe44b4f115952040f9dfdd23016da) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
c06b5e8aab782a8117419c28f7660e062701307c)


Input files
===========

$ cat asdf.h 
class A {};

$ cat ../.clang-format 
---
BraceWrapping:   
  AfterClass:      true
BreakBeforeBraces: Custom
...


Incorrect output
================

$ clang-format asdf.h 
class A {};


After recompile (see diff below)
================================

$ clang-format asdf.h 
class A
{};




The BraceWrapping flags mapped from file are all overwritten with false,
followed by assignment for whatever preset may have been specified. In default:
at the end of the switch (BS_Custom), it's too late.


Could fix with the following or equivalent:


diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 62f94b8..50ff2c1 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -363,6 +363,9 @@ std::string ParseErrorCategory::message(int EV) const {
 }

 static FormatStyle expandPresets(const FormatStyle &Style) {
+  if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
+    return Style;
+
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
                             false, false, false, false, false};</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>