Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Reference alignment options not honored for templated struct decltype(auto) operator() #66890

Closed
vient opened this issue Sep 20, 2023 · 4 comments · Fixed by #66904 or llvm/llvm-project-release-prs#770

Comments

@vient
Copy link
Member

vient commented Sep 20, 2023

$ cat test.cpp
template<typename T>
struct A {
    decltype(auto) operator()(T& x) {
        return x;
    }
};

template<typename T>
struct B {
    auto operator()(T& x) {
        return x;
    }
};

clang-format-17 test.cpp produces

template <typename T> struct A {
  decltype(auto) operator()(T & x) { return x; }
};

template <typename T> struct B {
  auto operator()(T &x) { return x; }
};

Note that in A it produces T & x, in B T &x

$ clang-format-17 --version
Ubuntu clang-format version 17.0.0 (++20230918073327+88bf774c5650-1~exp1~20230918073342.41)

I'll note, just in case, that lack of config does not matter, same happens when ReferenceAlignment is defined.

@rymiel
Copy link
Member

rymiel commented Sep 20, 2023

As expected this is a misannotation of the &, as BinaryOperator instead of the expected PointerOrReference, similarly, the operator keyword is annotated as Unknown, instead of the expected FunctionDeclarationName

AnnotatedTokens(L=1, P=0, T=5, C=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=decltype L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba0eb10 Text='decltype'
 M=0 C=0 T=TypeDeclarationParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=auto L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba1a458 Text='auto'
 M=0 C=0 T=TypeDeclarationParen S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=80 Name=operator L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba1b038 Text='operator'
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=24 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=25 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=OverloadedOperatorLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=26 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=identifier L=27 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba164a0 Text='T'
 M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=48 Name=amp L=29 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='&'
 M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=240 Name=identifier L=31 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba16500 Text='x'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=32 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=FunctionLBrace S=1 F=0 B=0 BK=1 P=23 Name=l_brace L=34 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'
AnnotatedTokens(L=1, P=0, T=5, C=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=auto L=4 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba1a458 Text='auto'
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=operator L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba1b038 Text='operator'
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=OverloadedOperatorLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=identifier L=17 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba164a0 Text='T'
 M=0 C=1 T=PointerOrReference S=1 F=0 B=0 BK=0 P=230 Name=amp L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='&'
 M=0 C=1 T=StartOfName S=0 F=0 B=0 BK=0 P=240 Name=identifier L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x55dc1ba16500 Text='x'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=FunctionLBrace S=1 F=0 B=0 BK=1 P=23 Name=l_brace L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'

@owenca
Copy link
Contributor

owenca commented Nov 8, 2023

/cherry-pick 67b99fa

@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2023

/branch llvm/llvm-project-release-prs/issue66890

@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2023

/pull-request llvm/llvm-project-release-prs#770

@tru tru moved this from Needs Triage to Needs Review in LLVM Release Status Nov 13, 2023
tru pushed a commit that referenced this issue Nov 13, 2023
@nikic nikic moved this from Needs Review to Done in LLVM Release Status Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment