<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 - Already formatted source code is changed on every clang-format run"
href="https://bugs.llvm.org/show_bug.cgi?id=39164">39164</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Already formatted source code is changed on every clang-format run
</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>Linux
</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>vg@glavny.org
</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=20954" name="attach_20954" title="example of cyclic mutating source code">attachment 20954</a> <a href="attachment.cgi?id=20954&action=edit" title="example of cyclic mutating source code">[details]</a></span>
example of cyclic mutating source code
This code (sample.cpp) is changed on each clang-format run:
<span class="quote">> int foo() {
> // clang-format off
> #define X 1
> // clang-format on
> return (X);
> }</span >
Test run:
<span class="quote">> clang-format sample.cpp > result_1.cpp
> clang-format result_1.cpp > result_2.cpp
> clang-format result_2.cpp > result_3.cpp </span >
Results:
sample.cpp != result_1.cpp
result_2.cpp != result_1.cpp
result_2.cpp == sample.cpp
result_3.cpp != result_2.cpp
result_3.cpp == result_1.cpp
To fix this, need to add one blank line before a preprocessor directive:
<span class="quote">> int foo_fixed() {
> // clang-format off
>
> #define X 1
> // clang-format on
> return (X);
> }</span >
This behavior has been checked in 6.0 and 7.0 under Linux and Windows.</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>