bloomberg/clang-p2996

is_accessible cannot return correct result for base classes

Closed this issue · 0 comments

Reflections of base classes (i.e., those returned by bases_of) are represented as pointers to CXXBaseSpecifier, which in a class definition like

struct Cls : private Base1, public virtual Base2 {};

represent the declarations private Base1 and public virtual Base2. It's important that we represent bases as CXXBaseSpecifier and not as QualType (as we represent other types), since we need to "remember" whether a base's accessibility, and whether or not it's virtual, to implement metafunctions like is_virtual and is_public.

There is, however, no "edge" from a CXXBaseSpecifier back to the derived class whose definition the base declaration forms a part of (i.e., no pointer to Cls from the CXXBaseSpecifier for Base1). This foils any attempt to implement is_accessible for base classes, since it can't be known whether e.g., a function that is a friend of Cls should "have access" to Cls::Base1.

Probably we just need to add that pointer to the derived class to the CXXBaseSpecifier class, but we haven't yet tried it.