[llvm-bugs] [Bug 50549] New: One constructor initializer per line

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 1 00:00:14 PDT 2021


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: unassignedclangbugs at nondot.org
          Reporter: nikolai.hlubek at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210601/c8c5fbf7/attachment.html>


More information about the llvm-bugs mailing list