Clang applies constraint checking loosely in variable declaration with concepts · Issue #54443 · llvm/llvm-project (original) (raw)

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 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