Re: Type traits and accessibility
On 13 Apr., 18:41, Nikolay Ivchenkov <ts...@mail.ru> wrote:
According to N3092 - 11/5,
"The interpretation of a given construct is established without regard
to access control. If the interpretation established makes use of
inaccessible member names or base classes, the construct is ill-
formed".
This is the general core language rule and applies to
everything which is does not say otherwise.
Does it mean that the following program is ill-formed?
#include <type_traits>
class X
{
public:
X() {}
private:
X(int) {}
};
int main()
{
int bool value =
std::is_constructible<X, int>::value;
}
This is well-formed, because std::is_constructible
needs compiler-support (same as is_convertible
does) to realize it's specification, see
[meta.unary.prop]/6:
"Given the following function prototype:
template <class T>
typename add_rvalue_reference<T>::type create();
the predicate condition for a template specialization
is_constructible<T, Args...> shall be satisfied if and
only if the following expression CE would be well-formed:
? if sizeof...(Args) == 1, the expression:
static_cast<T>(create<Args>()...)
? otherwise, the expression:
T(create<Args>()...)"
Note the usage of "would be well-formed". For your
example the effective test-expression is
static_cast<X>(create<int>())
This expression *would* be ill-formed, because
attempting to evaluate it inside main would
stumble across the lack of access here. The result
is, that the program is well-formed and that
"value" will evaluate to false.
It may well be that your current compiler declares
the program as ill-formed because it just simulates
the semantics via "normal" code. But this is not
a compliant implementation.
HTH & Greetings from Bremen,
Daniel Kr?gler
P.S.: Note that there is a open library issue in regard
to is_constructible, but it does not affect your example:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#1260
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]