[llvm-bugs] [Bug 25073] New: BreakBeforeBraces: Custom ignores BraceWrapping flags

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 6 07:12:08 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=25073

            Bug ID: 25073
           Summary: BreakBeforeBraces: Custom ignores BraceWrapping flags
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mattipee at yahoo.co.uk
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org
    Classification: Unclassified

$ clang-format -version

clang-format version 3.8.0 (http://llvm.org/git/clang.git
fad8a5cf2c6fe44b4f115952040f9dfdd23016da) (http://llvm.org/git/llvm.git
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};

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151006/6472e375/attachment.html>


More information about the llvm-bugs mailing list