Skip to content

[clang-format] RemoveParentheses option breaks fold expressions #90966

Closed
@A-Kovalev-Playrix

Description

@A-Kovalev-Playrix

With any option except Leave clang-format breaks code with fold expressions.

Test example:

template<class... TArgs>
struct TestParams {
  template<class... TArgsLocal>
  bool Test(TArgsLocal&&... args) noexcept {
    static_assert((... && std::is_convertible_v<TArgsLocal, TArgs>));

    if constexpr ((... && std::is_convertible_v<TArgsLocal, TArgs>)) {
      // something
    }

    return (... && std::is_convertible_v<TArgsLocal, TArgs>);
  }
};

after reformat it with option RemoveParentheses equals to ReturnStatement it will look like this:

template<class... TArgs>
struct TestParams
{
  template<class... TArgsLocal>
  bool Test(TArgsLocal&&... args) noexcept
  {
    static_assert(... && std::is_convertible_v<TArgsLocal, TArgs>);

    if constexpr (... && std::is_convertible_v<TArgsLocal, TArgs>) {
      // something
    }

    return ... && std::is_convertible_v<TArgsLocal, TArgs>;
  }
};

In result the code becomes invalid as fold expressions should always have parentheses around them. It would be great to have support of fold expressions and avoid removal of extra parentheses.

Tested it on clang-format version 18.1.5

Metadata

Metadata

Assignees

Labels

clang-formatinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions