Boost logo

Boost :

Subject: [boost] [concept_check] CopyConstructible Concept Does Not Accept Lvalue Reference
From: Qu Xing (matrix0932joeq_at_[hidden])
Date: 2018-10-11 07:34:41


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk