[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 18 12:05:49 PDT 2024
================
@@ -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();
----------------
ymand wrote:
optional super nit: save `&Base` instead, avoiding a call to `getType()` until after the loop.
https://github.com/llvm/llvm-project/pull/84138
More information about the cfe-commits
mailing list