[llvm-bugs] [Bug 42163] New: Clang-format PointerAlignment is Applied to Pointer to CV-qualified Pointer But Not Pointer to Pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 6 08:00:00 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42163

            Bug ID: 42163
           Summary: Clang-format PointerAlignment is Applied to Pointer to
                    CV-qualified Pointer But Not Pointer to Pointer
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: matthias.schaefer at versasec.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

.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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190606/7b1f7e6c/attachment.html>


More information about the llvm-bugs mailing list