clang-concepts-monorepo icon indicating copy to clipboard operation
clang-concepts-monorepo copied to clipboard

Concepts ignored in arguments to lambdas

Open EricJMarti opened this issue 4 years ago • 4 comments

https://godbolt.org/z/K0Yk2V

In the above example, it appears the concept constraints are not being validated in either lambda expression. I would have expected this example to fail compilation, suggesting that "struct bad" does not satisfy the "foobar" concept.

EricJMarti avatar Sep 19 '19 06:09 EricJMarti

Here is a reduced version of the bug that shows the problem is specific to lambdas, not functions or an equivalent function object:

template <typename T>
concept false_ = false;

auto lambda = [](false_ auto) {};
auto function(false_ auto) {}
struct {
    constexpr auto operator()(false_ auto) const {}
} function_object;

int main() {
    lambda(1); // accepts
    function(1); // rejects
    function_object(1); // rejects
}

davidstone avatar Sep 21 '19 00:09 davidstone

Note that it is specific to the terse syntax -- the following code is correctly rejected:

auto lambda = [](auto) requires false {};

int main() {
    lambda(1);
}

davidstone avatar Sep 21 '19 00:09 davidstone

This should be fixed with 37d1a85de3a1b09bdff5ff3caefe8bad880d30bd.

DanielBelow avatar Dec 12 '19 12:12 DanielBelow

Confirmed that this is fixed.

davidstone avatar Dec 12 '19 22:12 davidstone