Skip to content

Clang applies constraint checking loosely in variable declaration with concepts #54443

@ldionne

Description

@ldionne

The following code compiled with Clang, but not with GCC or MSVC:

template <class T, class U>
struct is_same { static constexpr bool value = false; };

template <class T>
struct is_same<T, T> { static constexpr bool value = true; };

template <class T, class U>
concept same_as = is_same<T, U>::value;

int const& f();

same_as<int const&> auto& i = f();

Both GCC and MSVC complain that the constraint same_as<int const&> is not satisfied, but Clang accepts it. If we change to same_as<int const> auto& i = f();, then GCC and MSVC accept it, and Clang accepts it too, which is really weird!

Godbolt: https://godbolt.org/z/q5K9885vb

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions