<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 PointerAlignment is Applied to Pointer to CV-qualified Pointer But Not Pointer to Pointer"
href="https://bugs.llvm.org/show_bug.cgi?id=42163">42163</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang-format PointerAlignment is Applied to Pointer to CV-qualified Pointer But Not Pointer to Pointer
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>matthias.schaefer@versasec.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>.clang-format file:
Language: Cpp
PointerAlignment: Left
After running clang-format the code is formatted as follows:
int* a;
int** b;
int* const* c;
int* const* const d;
As you can see, the pointer alignment is done once in line 2, but twice in
lines 3 and 4. I understand that the logic is most probably to look left and
right of each asterisk and to only apply the alignment if there is an
identifier, ignoring the fact that cv qualifiers are no identifiers. I want to
point out that ignoring the fact that cv qualifiers are no identifiers makes
this behavior actually illogical: A pointer does not get aligned when it has
zero cv qualifiers, but it does get aligned when it has one or more cv
qualifiers.
I would either expect the output of line 2 to be:
int* * b;
or the output of lines 3 and 4 to be:
int*const* c;
int*const*const d;
To solve this glitch, my proposal is to add new options to the PointerAlignment
setting:
- LeftAlways, applies Left alignment to each asterisk, corresponding to the 1st
solution,
- Type, applies Left alignment to the whole type only, corresponding to the 2nd
solution,
- RightAlways, applies Right alignment to each asterisk, which would yield "int
* *b" for line 2, and
- Declarator, applies Right alignment to the whole declarator only, which would
yield "int *const*c" for line 3.</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>