<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - clang-format vertical alignment of 2d array declarations, arrays of structs, and excessively long arrays."
   href="https://bugs.llvm.org/show_bug.cgi?id=40906">40906</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-format vertical alignment of 2d array declarations, arrays of structs, and excessively long arrays.
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>micasnyd@cisco.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Two-dimensional arrays, arrays of structs, and excessively long
single-dimension arrays that are formatted by clang-format end up being
extraordinarily lengthy as each element in each struct will be assigned a
separate line instead of being organized as a matrix.

Ideally, clang-format would format the 2nd dimension, or the entire struct (in
an array of structs), on one line, with each member variable aligned vertically
so as to appear as a table or matrix.

The following examples showing the need for this feature/improvement are from
the ClamAV project. I will note that for the time being we also disable
clang-format to align consecutive macros, which is a feature already in
[review](<a href="https://reviews.llvm.org/D28462">https://reviews.llvm.org/D28462</a>) that I am looking forward to using.

Array of Structs Declarations:

* libclamav/filestypes.c:
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/filetypes.c#L57">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/filetypes.c#L57</a>
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/filetypes.c#L226">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/filetypes.c#L226</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/matcher.h#L183">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/matcher.h#L183</a>
  * Note, this one contains edge case where the 2nd dimension contains an
additional struct as a member variable.

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/msxml.c#L52">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/msxml.c#L52</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/swf.h#L131">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/swf.h#L131</a>


2D Array Declarations:

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/htmlnorm.c#L129">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/htmlnorm.c#L129</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/pe_icons.c#L254">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/pe_icons.c#L254</a>

* libclamav/disasm.c contains many examples, although the variables in these
examples are unfortunately not aligned:
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L83">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L83</a>
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L94">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L94</a>
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L105">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L105</a>
  *
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L114">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/disasm.c#L114</a>
  * etc...


A related issue with single-dimension arrays where existing line-breaks need to
be respected is probably not addressable.

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/sf_base64decode.c#L31">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/sf_base64decode.c#L31</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/binhex.c#L36">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/binhex.c#L36</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/htmlnorm.c#L103">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/htmlnorm.c#L103</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/matcher-ac.c#L71">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/matcher-ac.c#L71</a>

*
<a href="https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/textdet.c#L58">https://github.com/Cisco-Talos/clamav-devel/blob/dev/0.102/libclamav/textdet.c#L58</a>


Additional detail about how the ClamAV project is using clang-format are listed
in this blog post:
<a href="https://blog.clamav.net/2019/02/clamav-adopts-clang-format.html">https://blog.clamav.net/2019/02/clamav-adopts-clang-format.html</a></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>