6
#include <type_traits>

int main()
{
    std::is_constructible_v<int&, const int&>; // false, as expected.
    std::is_copy_constructible_v<int&>; // true, NOT as expected!
}

According to cppref:

If T is an object or reference type and the variable definition T obj(std::declval()...); is well-formed, provides the member constant value equal to true. In all other cases, value is false.

std::is_copy_constructible_v<int&> should give the same result as std::is_constructible_v<int&, const int&> does; however, clang 7.0 gives different results as shown above.

Does this behavior conform to the C++ standards?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 1
    On the other hand `using T = int&; static_assert(std::is_constructible_v); // true` at least matches `is_copy_constructible_v` result. – dewaffled Feb 01 '19 at 07:28

1 Answers1

2

What the reference for is_copy_constructible states is:

If T is not a referenceable type (i.e., possibly cv-qualified void or a function type with a cv-qualifier-seq or a ref-qualifier), provides a member constant value equal to false. Otherwise, provides a member constant value equal to std::is_constructible<T, const T&>::value.

So, here is_copy_constructible<T>::value is the same as std::is_constructible<T, const T&>::value.

So in your case:

std::is_constructible<int, const int&>::value will be the same as std::is_copy_constructible_v<int>.

See DEMO

P.W
  • 26,289
  • 6
  • 39
  • 76