[concept_check] CopyConstructible Concept Does Not Accept Lvalue Reference

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[concept_check] CopyConstructible Concept Does Not Accept Lvalue Reference

Boost - Dev mailing list
Boost version: 1.67.0
Compiler: GCC 7.3.0
Environment: Cygwin on Windows 10 version 1709

In the Boost Concept Check library, CopyConstructible concept requires
operator & applicable to the type being checked, and the return value is
required to be convertible to pointer to the type.
However, pointer to reference is not allowed in C++.  This concept check
fails to compile if applying to a lvalue reference type.

On the other hand, is_copy_constructible<T> type trait class in the Boost
Type Traits library and the standard C++ library both give positive result
on lvalue reference types.

For example, the following code snippet will fail to compile if T is a
lvalue reference:

#include <type_traits>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_copy_constructible.hpp>
#include <boost/concept_check.hpp>
#include <boost/concept/assert.hpp>

template <typename T>
void RequireCopyConstructible()
{
    BOOST_STATIC_ASSERT(boost::is_copy_constructible<T>::value); // PASS on
lvalue reference
    BOOST_STATIC_ASSERT(std::is_copy_constructible<T>::value);   // PASS on
lvalue reference
    BOOST_CONCEPT_ASSERT((boost::CopyConstructible<T>));         // FAIL on
lvalue reference
}

void TestReference()
{
    RequireCopyConstructible<int&>();
}

Diagnosis message is generated as: "error: forming pointer to reference
type ‘int&’".

I think the operator & applicable requirement should be removed for
CopyConstructible concept.
Alternatively, adding a template specialization on lvalue reference type
for CopyConstructible concept may work as well.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost