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 16 doesn't respect BreakAfterAttributes option for constructors #63046

Closed
calcmogul opened this issue Jun 1, 2023 · 4 comments
Closed
Assignees

Comments

@calcmogul
Copy link

When the BreakAfterAttributes option in clang-format 16 is set to Always, it introduces a newline after attributes for member functions, but not for constructors. It seems like it should break after attributes for constructors as well.

Example input in a file called Test.cpp:

class Test {
public:
  [[deprecated]] Test(int);

  [[deprecated("msg")]] Test(double);

  [[deprecated]] void Func1();

  [[deprecated("msg")]] void Func2();
};

Command:

clang-format --style="{BreakAfterAttributes: Always}" Test.cpp

Expected output:

class Test {
public:
  [[deprecated]]
  Test(int);

  [[deprecated("msg")]]
  Test(double);

  [[deprecated]]
  void Func1();

  [[deprecated("msg")]]
  void Func2();
};

Actual output:

class Test {
public:
  [[deprecated]] Test(int);

  [[deprecated("msg")]] Test(double);

  [[deprecated]]
  void Func1();

  [[deprecated("msg")]]
  void Func2();
};
@calcmogul
Copy link
Author

calcmogul commented Jun 1, 2023

Here's the commit the option was added in:
a28f074

The comment True if breaking after last attribute group in function return type implies that the attribute breaking is tied to the return type, but constructors don't have return types.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 1, 2023

@llvm/issue-subscribers-clang-format

@owenca
Copy link
Contributor

owenca commented Jun 2, 2023

Actually, this is because clang-format doesn't annotate constructors as FunctionDeclarationName.

@owenca owenca self-assigned this Aug 15, 2023
@owenca
Copy link
Contributor

owenca commented Aug 15, 2023

@owenca owenca closed this as completed in 0e63f1a Aug 24, 2023
owenca added a commit that referenced this issue Aug 29, 2023
(0e63f1a was reverted by 7590b76 due to a crash.)

Annotate constructor/destructor names as FunctionDeclarationName.

Fixes #63046.

Differential Revision: https://reviews.llvm.org/D157963
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

4 participants