@@ -134,7 +134,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback BaseMatches) const {
134134 return false ;
135135
136136 CXXRecordDecl *Base =
137- cast_or_null <CXXRecordDecl>(Ty->getDecl ()->getDefinition ());
137+ cast_if_present <CXXRecordDecl>(Ty->getDecl ()->getDefinition ());
138138 if (!Base ||
139139 (Base->isDependentContext () &&
140140 !Base->isCurrentInstantiation (Record))) {
@@ -169,13 +169,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
169169 QualType BaseType =
170170 Context.getCanonicalType (BaseSpec.getType ()).getUnqualifiedType ();
171171
172+ bool isCurrentInstantiation = isa<InjectedClassNameType>(BaseType);
173+ if (!isCurrentInstantiation) {
174+ if (auto *BaseRecord = cast_if_present<CXXRecordDecl>(
175+ BaseSpec.getType ()->getAsRecordDecl ()))
176+ isCurrentInstantiation = BaseRecord->isDependentContext () &&
177+ BaseRecord->isCurrentInstantiation (Record);
178+ }
172179 // C++ [temp.dep]p3:
173180 // In the definition of a class template or a member of a class template,
174181 // if a base class of the class template depends on a template-parameter,
175182 // the base class scope is not examined during unqualified name lookup
176183 // either at the point of definition of the class template or member or
177184 // during an instantiation of the class tem- plate or member.
178- if (!LookupInDependent && BaseType->isDependentType ())
185+ if (!LookupInDependent &&
186+ (BaseType->isDependentType () && !isCurrentInstantiation))
179187 continue ;
180188
181189 // Determine whether we need to visit this base class at all,
@@ -243,9 +251,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
243251 return FoundPath;
244252 }
245253 } else if (VisitBase) {
246- CXXRecordDecl *BaseRecord;
254+ CXXRecordDecl *BaseRecord = nullptr ;
247255 if (LookupInDependent) {
248- BaseRecord = nullptr ;
249256 const TemplateSpecializationType *TST =
250257 BaseSpec.getType ()->getAs <TemplateSpecializationType>();
251258 if (!TST) {
@@ -264,8 +271,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
264271 BaseRecord = nullptr ;
265272 }
266273 } else {
267- BaseRecord = cast<CXXRecordDecl>(
268- BaseSpec.getType ()->castAs <RecordType>()->getDecl ());
274+ BaseRecord = cast<CXXRecordDecl>(BaseSpec.getType ()->getAsRecordDecl ());
269275 }
270276 if (BaseRecord &&
271277 lookupInBases (Context, BaseRecord, BaseMatches, LookupInDependent)) {
0 commit comments