<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 not idempotent with long comment containing tabs"
   href="https://bugs.llvm.org/show_bug.cgi?id=52466">52466</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-format not idempotent with long comment containing tabs
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>13.0
          </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>felix.widmaier@tue.mpg.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25437" name="attach_25437" title="Example file for which the described issue occurs.">attachment 25437</a> <a href="attachment.cgi?id=25437&action=edit" title="Example file for which the described issue occurs.">[details]</a></span>
Example file for which the described issue occurs.

The output of `clang-format` changes multiple times on this example containing
a long comment with tabs (this is extracted from a real-world example, reduced
to the offending line):

<span class="quote">> //     //                                                              for(auto const& value: sze) cout << value<<" ";</span >

(the file is also added as attachment).

I am testing with version "13.0.0 (<a href="https://github.com/llvm/llvm-project">https://github.com/llvm/llvm-project</a>
d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)".


Expected behaviour
==================

Calling `clang-format` a second time on any file should not result in any
additional changes, i.e. the output of

    $ clang-format file.cpp | clang-format --dry-run

should always be empty.


Actual behaviour
================

On the given example, 

    $ clang-format file.cpp | clang-format --dry-run

results in the following output:

<span class="quote">> <stdin>:1:37: warning: code should be clang-formatted [-Wclang-format-violations]
> //      //                                                              for(auto const& value: sze)
>                                                                                               ^
> <stdin>:1:42: warning: code should be clang-formatted [-Wclang-format-violations]
> //      //                                                              for(auto const& value: sze)
>                                                                                                    ^
> <stdin>:2:1: warning: code should be clang-formatted [-Wclang-format-violations]
> // cout << value<<" ";
> ^</span >

Actually, I have to call it four times until there are no changes anymore.


One run
-------

    $ clang-format file.cpp
    //  //                                                             
for(auto const& value: sze)
    // cout << value<<" ";

Two runs
--------

    $ clang-format file.cpp | clang-format
    //  //                                                             
for(auto const& value:
    // sze) cout << value<<" ";

Three runs
----------

    $ clang-format file.cpp | clang-format | clang-format
    //  //                                                             
for(auto const&
    // value: sze) cout << value<<" ";

Four runs
---------

    $ clang-format file.cpp | clang-format | clang-format | clang-format
    //  //                                                             
for(auto
    // const& value: sze) cout << value<<" ";

>From here there are no more changes.

I noticed that when I replace the tabs with spaces, I don't have this issue.</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>