21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.8 Member accessibility queries [meta.reflection.access.queries]

consteval bool is_accessible(info r, access_context ctx);
Let PARENT-CLS(r) be:
  • If parent_of(r) represents a class C, then C.
  • Otherwise, PARENT-CLS(parent_of(r)).
Constant When:
  • r does not represent a class member for which PARENT-CLS(r) is an incomplete class and
  • r does not represent a direct base class relationship for which D is incomplete.
Let DESIGNATING-CLS(r, ctx) be:
  • If ctx.designating_class() represents a class C, then C.
  • Otherwise, PARENT-CLS(r).
Returns:
  • If r represents an unnamed bit-field F, then is_accessible(, ctx), where 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():
[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())); // OK static_assert(!is_accessible(Cls::r, access_context::current())); // OK static_assert(is_accessible(Cls::r, access_context::unchecked())); // OK — end example]
consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);
Constant When:
  • nonstatic_data_members_of(​r, access_context​::​​unchecked()) is a constant subexpression and
  • r does not represent a closure type.
Returns: true if is_accessible(R, ctx) is false for any R in nonstatic_data_members_of(​r, access_context​​::​unchecked()).
Otherwise, false.
consteval bool has_inaccessible_bases(info r, access_context ctx);
Constant When: bases_of(r, access:context​::​unchecked()) is a constant subexpression.
Returns: true if is_accessible(R, ctx) is false for any R in bases_of(​r, access_context​::​​unchecked()).
Otherwise, false.
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);