Skip to content

Clang crashes with requires expression in lambda in concept constraints #64607

Closed
@namniav

Description

@namniav

https://godbolt.org/z/Kvr6afWd4

template<typename T> concept doesnt_matter = true;

template<class T>
concept test = 
    []{
        return requires(T t) {
            { t } -> doesnt_matter;
        };
    }();

static_assert(test<int>);

It is reduced from https://godbolt.org/z/5K6janbx5

#include <concepts>
#include <type_traits>
#include <utility>
#include <tuple>

template<class T>
concept tuple_like = 
    [] <std::size_t...I> (std::index_sequence<I...>) {
        return ((requires(T t) {
                    { std::get<I>(t) } -> std::convertible_to<std::tuple_element_t<I, T>&>;
                }) && ...);
    } (std::make_index_sequence<std::tuple_size_v<T>>{});

static_assert(tuple_like<std::tuple<int>>);

Both were accepted by Clang 15 and earlier. Clang 16 and current trunk on CompilerExplorer crashes on them(with either libc++ or libstdc++), but accepts the second if std::tuple_element_t<I, T>& is replaced with int&.

GCC also has this issue on the second example only: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105644.

MSVC accepts them.

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsconfirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions