Reputation: 385114
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. [..]
Upvotes: 16
Views: 577
Reputation: 476990
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.
Upvotes: 12
Reputation: 385114
From the second quote in the question, I'd say that accessibility is not affected by delete
dness, and that the first quote actually doesn't at all cover the case that such a constructor may be delete
d.
This scenario is instead covered by a sort of "catch-all" requirement in the definition of delete
:
[C++11: 8.4.3/2]:
A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed. [ Note: This includes calling the function implicitly or explicitly and forming a pointer or pointer-to-member to the function. It applies even for references in expressions that are not potentially-evaluated. If a function is overloaded, it is referenced only if the function is selected by overload resolution. —end note ]
So, cppreference.com could probably do with a note that there is a further criterion that applies to the is_move_constructible
trait, than simply whether the move constructor is accessible. And there's a further problem here, which is that MoveConstructible
can be satisfied by CopyConstructible
too†, so even the move constructor on its own is not strictly necessary.
This all raises another interesting point, though, that any possible implementation of is_move_constructible
must surely "refer" to the deleted move constructor, which renders the program ill-formed as stated in the quote above. Still, I suppose with SFINAE tricks an implementation can avoid actually becoming ill-formed.
† "A type with no move ctor at all but with a copy-ctor is move-constructible (constructible from an rvalue)." — DyP
Upvotes: 9