llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

QualifierAlignment not working on top-level const + typenames

Open carlosgalvezp opened this issue 3 years ago • 1 comments

Example input:

$ cat /tmp/main.cpp
#include <cstdint>

void foo(const std::int32_t x,
         const std::int32_t& y)
{}

Output:

$ ./clang-format --style="{QualifierAlignment: Right}" /tmp/main.cpp 
#include <cstdint>

void foo(const std::int32_t x, std::int32_t const &y) {}

The correct alignment is applied for the reference parameter, but not for the first (value) parameter.

carlosgalvezp avatar Aug 15 '22 13:08 carlosgalvezp

@llvm/issue-subscribers-clang-format

llvmbot avatar Aug 15 '22 13:08 llvmbot

@mydeveloperday I'm looking a bit at the code. It seems the reason why this doesn't work is that clang-format will only fix it if the type is a pointer, reference or rvalue reference:

    if (Next && Next->isOneOf(tok::star, tok::amp, tok::ampamp) &&

Why is that? Not even this code works then, even though it's documented

    // The case  `const Foo` -> `Foo const`

There's no unit tests for that case :(

carlosgalvezp avatar Sep 20 '22 12:09 carlosgalvezp

maybe this was overlooked because const on "by-value" arguments is discouraged

rconde01 avatar Dec 04 '22 16:12 rconde01

Yes, I can understand that. There are however a number of guidelines that require const to be applied to value arguments as well, so it's a use case that should be supported.

carlosgalvezp avatar Dec 04 '22 17:12 carlosgalvezp

@rymiel @mydeveloperday Do you have any input on this issue?

carlosgalvezp avatar Feb 23 '23 15:02 carlosgalvezp