Skip to content

clang c++20: Associated constraints added to a default constructor are excessively checked #60293

@frederick-vs-ja

Description

@frederick-vs-ja

In the following code snippet, the declaration of typedef-name CW is accepted by msvc and gcc, but rejected by clang. Godbolt link.

I think clang is probably buggy here. When determining whether decltype(ConstrainedWrapper<Wrapped>{std::declval<Wrapped>()}) is well-formed, clang seemly excessively requires the associated constraints of the default constructor to be satisfied, even if the default constructor is not selected.

#include <concepts>
#include <cstddef>
#include <utility>

struct NoDefaultCtor {
    constexpr explicit NoDefaultCtor(std::nullptr_t) {}
};

template<class T>
struct Wrapper {
    Wrapper() = default;
    constexpr explicit Wrapper(T x) : val(std::move(x)) {}

    T val{};
};

template<class T>
struct ConstrainedWrapper {
    ConstrainedWrapper() requires std::default_initializable<T> = default;

    constexpr explicit ConstrainedWrapper(T x) : val(std::move(x)) {}

    T val{};
};

using Wrapped             = Wrapper<NoDefaultCtor>;
using W [[maybe_unused]]  = decltype(Wrapper<Wrapped>{std::declval<Wrapped>()});
using CW [[maybe_unused]] = decltype(ConstrainedWrapper<Wrapped>{std::declval<Wrapped>()}); // <- clang is buggy here

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions