Skip to content
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

Incorrect formatting of lambdas inside brace initialisation when the return type has [] #52943

Closed
abt8601 opened this issue Jan 1, 2022 · 1 comment
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior clang-format

Comments

@abt8601
Copy link

abt8601 commented Jan 1, 2022

Here is a small example that demonstrates the bug:

#include <variant>

// Utilities for working with std::variant. Taken from
// https://en.cppreference.com/w/cpp/utility/variant/visit

template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr; }}, v);
}

} // namespace ns

After formatting:

#include <variant>

// Utilities for working with std::variant. Taken from
// https://en.cppreference.com/w/cpp/utility/variant/visit

template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr;
}
} // namespace ns
, v);
}

} // namespace ns

The bug also appears if the return type is std::unique_ptr<int[]>. It does not appear when the return type doesn't have [], e.g. int *.

I suspect that it's related to #27146 and #40694, but I'm not certain.

.clang-format:

BasedOnStyle: LLVM

clang-format --version:

clang-format version 13.0.0 (Fedora 13.0.0-3.fc35)
@mkurdej mkurdej added clang-format bug Indicates an unexpected problem or unintended behavior and removed new issue labels Jan 1, 2022
@mkurdej mkurdej self-assigned this Jan 3, 2022
@mkurdej
Copy link
Member

mkurdej commented Jan 3, 2022

Review: https://reviews.llvm.org/D116553.

@mkurdej mkurdej added the awaiting-review Has pending Phabricator review label Jan 3, 2022
@mkurdej mkurdej closed this as completed in e2b6e21 Jan 4, 2022
@asl asl removed the awaiting-review Has pending Phabricator review label Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-format
Projects
None yet
Development

No branches or pull requests

3 participants