5.8 KiB
[meta.reflection.access.queries]
21 Metaprogramming library [meta]
21.4 Reflection [meta.reflection]
21.4.9 Member accessibility queries [meta.reflection.access.queries]
consteval bool is_accessible(info r, access_context ctx);
Let PARENT-CLS(r) be:
Let DESIGNATING-CLS(r, ctx) be:
Returns:
-
If r represents an unnamed bit-field F, then is_accessible(rH, ctx), where rH represents a hypothetical non-static data member of the class represented by PARENT-CLS(r) with the same access as F. [Note 1: Unnamed bit-fields are treated as class members for the purpose of is_accessible. â end note]
-
Otherwise, if r does not represent a class member or a direct base class relationship, then true.
-
Otherwise, if r represents
a class member that is not a (possibly indirect or variant) member of DESIGNATING-CLS(r, ctx) or
a direct base class relationship such that parent_of(r) does not represent DESIGNATING-CLS(r, ctx) or a (direct or indirect) base class thereof,
then false.
-
Otherwise, if ctx.scope() is the null reflection, then true.
-
Otherwise, letting P be a program point whose immediate scope is the function parameter scope, class scope, or namespace scope corresponding to the function, class, or namespace represented by ctx.scope():
-
If r represents a direct base class relationship (D,B), then true if base class B of DESIGNATING-CLS(r, ctx) is accessible at P ([class.access.base]); otherwise false.
-
Otherwise, r represents a class member M; true if M would be accessible at P with the designating class ([class.access.base]) as DESIGNATING-CLS(r, ctx) if the effect of any using-declarations ([namespace.udecl]) were ignored. Otherwise, false.
-
[Note 2:
The definitions of when a class member or base class is accessible from a point P do not consider whether a declaration of that entity is reachable from P.
â end note]
[Example 1: consteval access_context fn() {return access_context::current();}class Cls {int mem; friend consteval access_context fn();public:static constexpr auto r = ^^mem;};
static_assert(is_accessible(Cls::r, fn())); // OKstatic_assert(!is_accessible(Cls::r, access_context::current())); // OKstatic_assert(is_accessible(Cls::r, access_context::unchecked())); // OK â end example]
Throws: meta::exception if
r represents a class member for which PARENT-CLS(r) is an incomplete class or
r represents a direct base class relationship (D,B) for which D is incomplete.
consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);
Returns: true if is_accessible(R, ctx) is false for any R in nonstatic_data_members_of(r, access_context::unchecked()).
Otherwise, false.
Throws: meta::exception unless
nonstatic_data_members_of(r, access_context::unchecked()) is a constant subexpression and
r does not represent a closure type.
consteval bool has_inaccessible_bases(info r, access_context ctx);
Returns: true if is_accessible(R, ctx) is false for any R in bases_of(r, access_context::unchecked()).
Otherwise, false.
Throws: meta::exception unlessbases_of(r, access_context::unchecked()) is a constant subexpression.
consteval bool has_inaccessible_subobjects(info r, access_context ctx);
Effects: Equivalent to:return has_inaccessible_bases(r, ctx) || has_inaccessible_nonstatic_data_members(r, ctx);