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

            Bug ID: 50549
           Summary: One constructor initializer per line
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: nikolai.hlu...@gmail.com
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

It is not possible with clang format to always have one constructor initializer
per line no matter what. 

ConstructorInitializerAllOnOneLineOrOnePerLine only works in cases when the
line length is exceeded. This is ok if you have a line length of 80 characters.
If you have 160 characters (because of doxygen etc.) it looks horrible.

The first attempt to fix this goes back to 2015 and this review has been
getting comments ever since:
https://reviews.llvm.org/D14484#2788953
There is also a stackoverflow question about this:
https://stackoverflow.com/questions/56811537/clang-format-how-to-keep-each-element-of-constructors-initializer-list-on-a-se


Unit test for  unittests/Format/FormatTest.cpp
that explains in code what I am tring to achieve and what does not work:
TEST_F(FormatTest, ConstructorInitializerAllOnOneLineOrOnePerLine_AlwaysBreak)
{
  FormatStyle Style = getLLVMStyle();
  Style.ColumnLimit = 160;
  Style.BinPackParameters = false;
  Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
  Style.AllowAllConstructorInitializersOnNextLine = false;
  Style.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
  verifyFormat("Constructor() :\n"
               "    aaaaaaaaaaaaaaaaaa(a),\n"
               "    bbbbbbbbbbbbbbbbbbbbb(b) {}",
               Style);
}


In my opinion this is not difficult to fix and I already have a proof of
concept ready on github:
https://github.com/Nikolai-Hlubek/clang/tree/ConstructorInitializer_AlwaysBreakAfterColon

It would really be nice to get this fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to