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

[Format] clang-format recognizes */& as a PointerOrReference when operator is called as a non-member function #49973

Closed
Nuullll opened this issue Jun 9, 2021 · 2 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang-format

Comments

@Nuullll
Copy link
Contributor

Nuullll commented Jun 9, 2021

Bugzilla Link 50629
Version trunk
OS All

Extended Description

The following code:

void f() { operator+(a, b * b); }

Format with command:

clang-format b.cpp  --debug-only=format-token-annotator

Output:

AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=void L=4 PPK=2 FakeLParens= FakeRParens=0 II=0x19c6078 Text='void'
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=identifier L=6 PPK=2 FakeLParens= FakeRParens=0 II=0x19c36b0 Text='f'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=7 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=r_paren L=8 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=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'
----
AnnotatedTokens(L=1):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=operator L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x19c6670 Text='operator'
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=33 Name=plus L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='+'
 M=0 C=0 T=OverloadedOperatorLParen S=0 F=0 B=0 BK=0 P=33 Name=l_paren L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=59 Name=identifier L=11 PPK=2 FakeLParens=1/ FakeRParens=0 II=0x19c36e0 Text='a'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=41 Name=comma L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=','
 M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=41 Name=identifier L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x19c3710 Text='b'
 M=0 C=1 T=PointerOrReference S=1 F=0 B=0 BK=0 P=230 Name=star L=16 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=17 PPK=2 FakeLParens= FakeRParens=1 II=0x19c3710 Text='b'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=18 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
----
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=r_brace L=1 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='}'
----
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=eof L=0 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=''
----
void f() { operator+(a, b *b); }
@Nuullll
Copy link
Contributor Author

Nuullll commented Jun 9, 2021

assigned to @Nuullll

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@rymiel rymiel assigned rymiel and unassigned Nuullll Jun 26, 2023
@rymiel
Copy link
Member

rymiel commented Jun 26, 2023

Patch: https://reviews.llvm.org/D153798

@rymiel rymiel added the awaiting-review Has pending Phabricator review label Jun 26, 2023
@rymiel rymiel closed this as completed in 4986f3f Jun 29, 2023
owenca added a commit that referenced this issue Jul 4, 2023
Reverts 4986f3f (but keeps its unit tests) and fixes #49973
differently.

Also fixes bugs that incorrectly annotate the operator keyword as
TT_FunctionDeclarationName in function calls and as TT_Unknown in function
declarations and definitions.

Differential Revision: https://reviews.llvm.org/D154184
@owenca owenca removed the awaiting-review Has pending Phabricator review label Jul 6, 2023
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Sep 3, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
The annotator correctly annotates an overloaded operator call when
called as a member function, like `x.operator+(y)`, however, when called
as a free function, like `operator+(x, y)`, the annotator assumed it was
an overloaded operator function *declaration*, instead of a call.

This patch allows for a free function call to correctly be annotated as
a call, but only if the current like cannot be a declaration, usually
within the bodies of a function.

Fixes llvm/llvm-project#49973

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay, Nuullll

Differential Revision: https://reviews.llvm.org/D153798
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-format
Projects
None yet
Development

No branches or pull requests

3 participants