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] auto variable initialized with arrow operator can be seen as trailing return type #61469

Closed
rymiel opened this issue Mar 17, 2023 · 2 comments
Assignees

Comments

@rymiel
Copy link
Member

rymiel commented Mar 17, 2023

Input code:

auto a = (b)->c;

Result from clang-format-17 (main), with default style ({}):

auto a = (b) -> c;

The arrow is annotated as a trailing return type arrow due to an imperfect heuristic in determineTokenType.

This also applies to decltype(auto):

decltype(auto) a = (b) -> c;

This issue isn't encountered without the (redundant) parentheses:

auto a = b->c;

Originally discovered in https://reviews.llvm.org/D141811; I planned to make a fix for it there, but it turned out harder than I expected, so I'm adding an issue for it so I don't forget.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 17, 2023

@llvm/issue-subscribers-clang-format

@rymiel
Copy link
Member Author

rymiel commented Apr 1, 2023

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

@rymiel rymiel added the awaiting-review Has pending Phabricator review label Apr 1, 2023
@rymiel rymiel self-assigned this Apr 1, 2023
@rymiel rymiel closed this as completed in fd86789 Apr 3, 2023
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Apr 3, 2023
gysit pushed a commit to nextsilicon/llvm-project that referenced this issue Apr 27, 2023
The heuristic for determining if an arrow is a trailing return arrow
looks for the auto keyword, along with parentheses. This isn't
sufficient, since it also triggers on variable declarations with an auto
type, and with an arrow operator.

This patch makes sure a function declaration is being parsed, instead of
any other declaration.

Fixes llvm#61469

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D147377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants