<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-diff.py doesn't format impacted scope."
href="https://bugs.llvm.org/show_bug.cgi?id=42598">42598</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-format-diff.py doesn't format impacted scope.
</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>yvesg@google.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>To reproduce, remove conditional scope in the following code:
; code1 ...
if (predicate) {
; code2 ...
}
So we get:
; code1 ...
; code2 ...
Then clang-diff-format.py won't unindent `code2` block, since it wasn't
touched.
A real-life example involving scoped lock is shown [here][1].
I know we are pretty close from "works as intended" and that an obvious
workaround is to clang-format whole file.
That being said, I'd like to offer some suggestions:
### Suggestion 0
Drop this script altogether and always format whole files. That would improve
consistency.
### Suggestion 1
Introduce an option in `clang-format` to fix impacted lines as well (transitive
formatting).
### Suggestion 2
Pass formatting range to be [min_line_changed:max_line_changed+1].
That's less drastic than #0 and I think it would do the right thing more often.
### Suggestion 3
Document this very caveat.
[1]
<a href="https://webrtc-review.googlesource.com/c/src/+/125240/2/media/engine/webrtc_video_engine.cc#723">https://webrtc-review.googlesource.com/c/src/+/125240/2/media/engine/webrtc_video_engine.cc#723</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>