A deleted answer on this question about a deleted move constructor quotes cppreference.com as saying that the is_move_constructible
trait should succeed as long as a move constructor is "accessible", even if it's not "usable".
The standard in fact requires that move-construction of the argument type be well-formed, so the answer was not quite right.
Now, the standard repeatedly uses the term "accessible" in relation to constructors referring to actual constructibility. For example:
[C++11 8.5/6]:
To default-initialize an object of typeT
means:
- if
T
is a (possibly cv-qualified) class type (Clause 9), the default constructor forT
is called (and the initialization is ill-formed ifT
has no accessible default constructor);- if
T
is an array type, each element is default-initialized;- otherwise, no initialization is performed.
If a program calls for the default initialization of an object of a const-qualified type
T
,T
shall be a class type with a user-provided default constructor.
However, I can't find anywhere in the standard that states categorically whether a delete
d, explicitly-defined constructor is "accessible" or not.
A different [non-normative] quote seems to suggest that delete
d-ness and accessibility are orthogonal:
[C++11: 12.2/1]:
[..] [ Note: even if there is no call to the destructor or copy/move constructor, all the semantic restrictions, such as accessibility (Clause 11) and whether the function is deleted (8.4.3), shall be satisfied. [..]
I don't want to address what the cppreference website says, but as far as the standard is concerned, constructibility is not defined in terms of "accessible constructors". Rather, the primary definition is that of is_constructible
, which is (C++11, 20.9.4.3/6):
is_constructible<T, Args...>
shall be satisfied if and only if the following variable definition would be well-formed for some invented variable
t
:T t(create<Args>()...);
Access checking is performed as if in a context unrelated to
T
and any of theArgs
. Only the validity of the immediate context of the variable initialization is considered.
So the well-formedness of the hypothetical expression on the last line of code is the defining characteristic for the constructibility traits. And that works hand-in-hand with the clause that says that using a deleted function leads to an ill-formed program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With