[meta.reflection.access.queries]

# 21 Metaprogramming library [[meta]](./#meta)

## 21.4 Reflection [[meta.reflection]](meta.reflection#access.queries)

### 21.4.9 Member accessibility queries [meta.reflection.access.queries]

[ð](#lib:is_accessible)

`consteval bool is_accessible(info r, access_context ctx);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5241)

Let *PARENT-CLS*(r) be:

- [(1.1)](#1.1)

  If parent_of(r) represents a class C, then C[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  Otherwise, *PARENT-CLS*(parent_of(r))[.](#1.2.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5248)

Let *DESIGNATING-CLS*(r, ctx) be:

- [(2.1)](#2.1)

  If ctx.designating_class() represents a class C, then C[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  Otherwise, *PARENT-CLS*(r)[.](#2.2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5255)

*Returns*: 

- [(3.1)](#3.1)

  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[.](#3.1.sentence-1)
  [*Note [1](#note-1)*:
  Unnamed bit-fields are treated as class members
 for the purpose of is_accessible[.](#3.1.sentence-2)
 â *end note*]

- [(3.2)](#3.2)

  Otherwise, if r does not represent a class member
 or a direct base class relationship,
 then true[.](#3.2.sentence-1)

- [(3.3)](#3.3)

  Otherwise, if r represents
  * [(3.3.1)](#3.3.1)

a class member that is not a (possibly indirect or variant)
 member of *DESIGNATING-CLS*(​r, ctx) or

  * [(3.3.2)](#3.3.2)

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[.](#3.3.sentence-1)

- [(3.4)](#3.4)

  Otherwise, if ctx.scope() is the null reflection,
 then true[.](#3.4.sentence-1)

- [(3.5)](#3.5)

  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():
  * [(3.5.1)](#3.5.1)

      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]](class.access.base "11.8.3 Accessibility of base classes and base class members"));
 otherwise false[.](#3.5.1.sentence-1)

  * [(3.5.2)](#3.5.2)

      Otherwise, r represents a class member M; true if M would be accessible at P with the designating class ([[class.access.base]](class.access.base "11.8.3 Accessibility of base classes and base class members")) as *DESIGNATING-CLS*(r, ctx) if the effect of any [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]")*s* ([[namespace.udecl]](namespace.udecl "9.10 The using declaration")) were ignored[.](#3.5.2.sentence-1)
      Otherwise, false[.](#3.5.2.sentence-2)

[*Note [2](#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[.](#3.sentence-2)

â *end note*]

[*Example [1](#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*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5330)

*Throws*: meta​::​exception if

- [(4.1)](#4.1)

r represents a class member
 for which *PARENT-CLS*(r) is an incomplete class or

- [(4.2)](#4.2)

r represents a direct base class relationship (D,B) for which D is incomplete[.](#4.sentence-1)

[ð](#lib:has_inaccessible_nonstatic_data_members)

`consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5349)

*Returns*: true if is_accessible(R, ctx) is false for any R in nonstatic_data_members_of(​r, access_context​​::​unchecked())[.](#5.sentence-1)

Otherwise, false[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5355)

*Throws*: meta​::​exception unless

- [(6.1)](#6.1)

nonstatic_data_members_of(​r, access_context​::​​unchecked()) is a constant subexpression and

- [(6.2)](#6.2)

r does not represent a closure type[.](#6.sentence-1)

[ð](#itemdecl:3)

`consteval bool has_inaccessible_bases(info r, access_context ctx);
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5372)

*Returns*: true if is_accessible(R, ctx) is false for any R in bases_of(​r, access_context​::​​unchecked())[.](#7.sentence-1)

Otherwise, false[.](#7.sentence-2)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5378)

*Throws*: meta​::​exception unlessbases_of(r, access_context​::​unchecked()) is a constant subexpression[.](#8.sentence-1)

[ð](#lib:has_inaccessible_subobjects)

`consteval bool has_inaccessible_subobjects(info r, access_context ctx);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5391)

*Effects*: Equivalent to:return has_inaccessible_bases(r, ctx) || has_inaccessible_nonstatic_data_members(r, ctx);
