Skip to content

[clang-format] Incorrect method body when combining trailing return type & decltype in requires clause #78645

Closed
@helmesjo

Description

@helmesjo

Continuation of #56176 (@HazardyKnusperkeks).

Tweaking the original example in that issue by adding & to the trailing return and using decltype(...) in the requires clause breaks it:

  template<typename T>
  struct Foo
  {
    auto bar(T in) -> int& requires (is_integral_v<decltype(in)>) {
                             call_something();
                             return 0;
                           }
  };

Changing one of the following fixes the formatting again:

  • -> int& to -> int
  • decltype(in) to T
  • requires (...) to requires ...

You need parens if you negate ((!...)), but I guess a (highly arbitrary looking) workaround is to change from
requires (is_integral_v<decltype(in)>)
to
requires is_integral_v<decltype(in)> || true
works (tested).

$ clang++ --version
Homebrew clang version 17.0.6

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorclang-format

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions