-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 options for attributes, ability to specify custom attributes. #45968
Comments
I think you are only talking about breaking after an attribute when that attribute is part of the return type correct? should
become
|
I'm interested in two situations primarily:
I'm not concerned about:
|
I would also prefer an option to move all identifiers and attributes that come before the return type to a separate line above. As C++ gains more and more keywords that inflate the function like:
The function declaration just gets too long. Additionally other languages also put the prefix attributes on the line above. I.e.: Java and C#. |
I was unable to do better for __host__ and __device__: see llvm/llvm-project/issues/45968
Extended Description
Clang-format currently does not have options to control attribute formatting.
Some projects prefer to put prefix attributes on a separate line, eg:
instead of:
[[nodiscard]] int foo();
Additionally, it would be useful to be able to provide a list of regexes that identify custom attributes. Maintaining an exhaustive list of attributes in clang-format proper would be daunting, as many projects hide them behind macros for backward compatibility, or rely on platform-specific attributes. Allowing projects to extend the list of recognized attributes would be quite useful.
My personal interest in this stems from using clang-format on CUDA projects, where
__host__ __device__
annotations are frequently used and commonly placed on the line above a function definition. Being able to achieve this common formatting style would ease adoption of clang-format by CUDA projects.The text was updated successfully, but these errors were encountered: