================ @@ -119,20 +119,28 @@ QualType getPublicType(const Expr *E) { return Ty; } - QualType Ty = getPublicType(Cast->getSubExpr()); - - // Is `Ty` the type of `*this`? In this special case, we can upcast to the - // base class even if the base is non-public. - bool TyIsThisType = isa<CXXThisExpr>(Cast->getSubExpr()); - + // Is the derived type that we're casting from the type of `*this`? In this + // special case, we can upcast to the base class even if the base is + // non-public. + bool CastingFromThis = isa<CXXThisExpr>(Cast->getSubExpr()); + + // Find the least-derived type in the path (i.e. the last entry in the list) + // that we can access. + QualType Ty; for (const CXXBaseSpecifier *Base : Cast->path()) { - if (Base->getAccessSpecifier() != AS_public && !TyIsThisType) + if (Base->getAccessSpecifier() != AS_public && !CastingFromThis) break; Ty = Base->getType(); ---------------- martinboehme wrote:
Done. More importantly than the minor efficiency gain, I think this makes the code more self-documenting. Thanks! https://github.com/llvm/llvm-project/pull/84138 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits