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 AlignAfterOpenBracket: BlockIndent improperly breaks after function pointer name #58496

Closed
jaskij opened this issue Oct 20, 2022 · 5 comments
Assignees

Comments

@jaskij
Copy link

jaskij commented Oct 20, 2022

When using Clang-Format with C it seems that function pointers are handled improperly. A break is inserted before the closing parenthesis after pointer name. It seems that the variable name is treated as an argument and shenanigans ensue.

Consider the following code - this is how clang-format formats it right now:

int (*tps25750_write
)(void*    ctx,
  uint8_t  tps_address,
  uint8_t  reg_address,
  uint8_t  byte_count,
  uint8_t* buffer);

I would expect it to look like this, closer to a function declaration (all my indents are set to 4 spaces):

int (*tps25750_write)(
    void*    ctx,
    uint8_t  tps_address,
    uint8_t  reg_address,
    uint8_t  byte_count,
    uint8_t* buffer
    );

Full .clang-format. That file mistakenly contained options from Clang-Format 16. Current file which actually works with Clan-Format 14

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 20, 2022

@llvm/issue-subscribers-clang-format

@gedare
Copy link
Contributor

gedare commented Nov 10, 2022

I proposed a fix at https://reviews.llvm.org/D137762. I could not reproduce your exact scenario, but I did create a simple test case that is similar.

@jaskij
Copy link
Author

jaskij commented Nov 10, 2022

Looking at the comments and examples in the fix, this does look like what I'd want.

Do you want me to try and reduce my code to a minimal reproducible example for another test case?

@rymiel rymiel added the awaiting-review Has pending Phabricator review label Nov 10, 2022
@gedare
Copy link
Contributor

gedare commented Nov 11, 2022

Looking at the comments and examples in the fix, this does look like what I'd want.

Do you want me to try and reduce my code to a minimal reproducible example for another test case?

No, I think I have the testing side figured out. There are a few corner cases that don't work quite right still. I'm hopeful to work it out though.

@owenca
Copy link
Contributor

owenca commented Dec 6, 2022

Fixed in b40e9dc.

@owenca owenca closed this as completed Dec 6, 2022
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Dec 6, 2022
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

6 participants