Skip to content

Commit 66f3465

Browse files
committed
[clang] Fix name lookup for dependent bases
1 parent b2d2494 commit 66f3465

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

clang/lib/AST/CXXInheritance.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
169169
// Find the record of the base class subobjects for this type.
170170
QualType BaseType =
171171
Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
172+
bool isCurrentInstantiation = isa<InjectedClassNameType>(BaseType);
172173

173174
// C++ [temp.dep]p3:
174175
// In the definition of a class template or a member of a class template,
175176
// if a base class of the class template depends on a template-parameter,
176177
// the base class scope is not examined during unqualified name lookup
177178
// either at the point of definition of the class template or member or
178179
// during an instantiation of the class tem- plate or member.
179-
if (!LookupInDependent && BaseType->isDependentType())
180+
if (!LookupInDependent &&
181+
(BaseType->isDependentType() && !isCurrentInstantiation))
180182
continue;
181183

182184
// Determine whether we need to visit this base class at all,
@@ -244,9 +246,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
244246
return FoundPath;
245247
}
246248
} else if (VisitBase) {
247-
CXXRecordDecl *BaseRecord;
249+
CXXRecordDecl *BaseRecord = nullptr;
248250
if (LookupInDependent) {
249-
BaseRecord = nullptr;
250251
const TemplateSpecializationType *TST =
251252
BaseSpec.getType()->getAs<TemplateSpecializationType>();
252253
if (!TST) {
@@ -265,8 +266,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
265266
BaseRecord = nullptr;
266267
}
267268
} else {
268-
BaseRecord = cast<CXXRecordDecl>(
269-
BaseSpec.getType()->castAs<RecordType>()->getDecl());
269+
BaseRecord = cast<CXXRecordDecl>(BaseSpec.getType()->getAsRecordDecl());
270270
}
271271
if (BaseRecord &&
272272
lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {

clang/test/CXX/drs/cwg5xx.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,17 +1178,21 @@ namespace cwg590 { // cwg590: yes
11781178
template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {}
11791179
}
11801180

1181-
namespace cwg591 { // cwg591: no
1181+
namespace cwg591 { // cwg591: yes
11821182
template<typename T> struct A {
11831183
typedef int M;
11841184
struct B {
11851185
typedef void M;
11861186
struct C;
1187+
struct D;
11871188
};
11881189
};
11891190

11901191
template<typename T> struct A<T>::B::C : A<T> {
1191-
// FIXME: Should find member of non-dependent base class A<T>.
1192+
M m;
1193+
};
1194+
1195+
template<typename T> struct A<T>::B::D : A<T*> {
11921196
M m;
11931197
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
11941198
};

0 commit comments

Comments
 (0)