This problem is based on code that works for me on GCC-4.6 but not for another user with CLang-3.0, both in C++0x mode.
template <typename T>
struct MyBase
{
//protected:
T m;
template <typename Args...>
MyBase( Args&& ...x ) : m( std::forward<Args>(x)... ) {}
};
An object of MyBase
can take any list of constructor arguments, as long as T
supports that construction signature. The problem has to do with the special-member functions.
- IIUC, the constructor template cancels the automatically-defined default constructor. However, since the template can accept zero arguments, it will act as an explicitly-defined default constructor (as long as
T
is default-constructible). - IIUC, determination of a class' copy-construction policy ignores constructor templates. That means in this case that
MyBase
will gain an automatically-defined copy constructor (as long asT
is copyable) that'll channelT
copy-construction. - Apply the previous step for move-construction too.
So if I pass a MyBase<T> const &
as the sole constructor argument, which constructor gets called, the forwarding one or the implicit copying one?
typedef std::vector<Int> int_vector;
typedef MyBase<int_vector> VB_type;
int_vector a{ 1, 3, 5 };
VB_type b{ a };
VB_type c{ b }; // which constructor gets called
My user's problem was using this in as a base class. The compiler complained that his class couldn't synthesize an automatically-defined copy constructor, because it couldn't find a match with the base class' constructor template. Shouldn't it be calling MyBase
automatic copy-constructor for its own automatic copy-constructor? Is CLang in error for coming up with a conflict?