Skip to content

clang-format: Add options for SpacesInParentheses #55428

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

Open
Hedede opened this issue May 13, 2022 · 3 comments
Open

clang-format: Add options for SpacesInParentheses #55428

Hedede opened this issue May 13, 2022 · 3 comments
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@Hedede
Copy link

Hedede commented May 13, 2022

I am working on a project where function declarations and functions calls are formatted differently:
void foo( Arg x, Arg y ); // decl
foo(a, b) // call

From what I could gather, SpacesInParentheses doens't support differentiation. There are SpacesInCStyleCastParentheses, SpacesInConditionalStatement, but that' snot enough.

I suggest to add something analogous to BraceWrapping

  • FunctionDecl (maybe also MemberFunctionDecl? I don't think it's needed though) void foo(A a)
  • FunctionCall foo(x)
  • FunctionLikeMacroDecl #define FOO( x )
  • FunctionLikeMacroCall FOO(x)
  • TemplateDecl template<typename T>
  • TemplateInstantiation Foo<T>
  • ConditionalStatement
  • Operator (sizeof, alignof...)
  • Decltype
  • Expression ( a + b )
  • CStyleCast
  • Braced initializer list
  • ... Maybe more?
@llvmbot
Copy link
Member

llvmbot commented May 13, 2022

@llvm/issue-subscribers-clang-format

@mkurdej mkurdej added the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label May 27, 2022
@gedare
Copy link
Contributor

gedare commented Jul 13, 2023

I have submitted https://reviews.llvm.org/D155239 to enable the possibility to add these finer-grained controls of space insertion.

owenca pushed a commit that referenced this issue Jul 25, 2023
This is a refactoring of:
- SpacesInConditionalStatement
- SpacesInCStyleCastParentheses
- SpaceInEmptyParentheses
- SpacesInParentheses

These are now options under the new Style Option: SpacesInParens. The
existing options are maintained for backward compatibility.

Within SpacesInParens, there are currently options for:
- Never
- Custom

The currently available options for Custom are:
- InConditionalStatements
- InCStyleCasts
- InEmptyParentheses
- Other

Setting InConditionalStatements and Other to true enables the same space
additions as SpacesInParentheses.

This refactoring does not add or remove any existing features, but it makes
it possible to more easily extend and maintain the addition of spaces within
parentheses.

Related to #55428.

Differential Revision: https://reviews.llvm.org/D155239
@gedare
Copy link
Contributor

gedare commented Jul 26, 2023

I have submitted https://reviews.llvm.org/D156360 to add the requested control over spaces inside of function calls vs function declarations.

gedare added a commit to gedare/llvm-project that referenced this issue Jan 9, 2024
This change separates function calls, declarations, definitions, and
overloaded operators from `SpacesInParensOptions.Other` to allow control
over each independently.

Fixes llvm#55428.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

No branches or pull requests

5 participants