The original code is checking for inaccessible base classes but does not expect inheriting from template parameters (or dependent types in general) as these are not modelled by CXXRecord.
Issue was at this line since getAsCXXRecord() returned nullptr:
bool found = Class->isDerivedFrom(CanonicalBase->getAsCXXRecordDecl(), Paths);
that base -> that the base