Skip to content

clang-format incorrectly indents lambda trailing return when lambda has constexpr specifier or noexcept specifier without expression #94181

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

Closed
carljohnson93 opened this issue Jun 3, 2024 · 0 comments · Fixed by #94560

Comments

@carljohnson93
Copy link

.clang-format:

BasedOnStyle: Google

Here is the formatted code when lambda doesn't have constexpr/noexcept specifier:

#include <type_traits>

void very_long_function_name_yes_it_is_really_long(...);

void do_something(...);

int main() {
  very_long_function_name_yes_it_is_really_long(
      [](auto n)
          -> std::enable_if_t<
              std::is_arithmetic<decltype(n)>::value &&
              !std::is_same<std::remove_cv_t<decltype(n)>, bool>::value> {
        do_something(n * 2);
      });
}

As expected trailing return arrow is indented 4 spaces after the lambda. But adding constexpr or noexcept specifier after lambda makes it 0 spaces:

#include <type_traits>

void very_long_function_name_yes_it_is_really_long(...);

void do_something(...);

int main() {
  very_long_function_name_yes_it_is_really_long(
      // also happens with constexpr specifier
      [](auto n) noexcept
      -> std::enable_if_t<
          std::is_arithmetic<decltype(n)>::value &&
          !std::is_same<std::remove_cv_t<decltype(n)>, bool>::value> {
        do_something(n * 2);
      });
}

Somewhat surprisingly, this issue doesn't happen when noexcept specifier with expression is used (e.g. noexcept(true)).

clang-format version: 17.0.6
OS: EndeavourOS Linux, kernel 6.9.3-arch1-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant