Skip to content

Commit 0de2ff2

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

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

clang/lib/AST/CXXInheritance.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,19 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
170170
QualType BaseType =
171171
Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
172172

173+
bool isCurrentInstantiation = false;
174+
if (auto *BaseRecord =
175+
cast<CXXRecordDecl>(BaseSpec.getType()->getAsRecordDecl()))
176+
isCurrentInstantiation = BaseRecord->isDependentContext() &&
177+
BaseRecord->isCurrentInstantiation(Record);
173178
// C++ [temp.dep]p3:
174179
// In the definition of a class template or a member of a class template,
175180
// if a base class of the class template depends on a template-parameter,
176181
// the base class scope is not examined during unqualified name lookup
177182
// either at the point of definition of the class template or member or
178183
// during an instantiation of the class tem- plate or member.
179-
if (!LookupInDependent && BaseType->isDependentType())
184+
if (!LookupInDependent &&
185+
(BaseType->isDependentType() && !isCurrentInstantiation))
180186
continue;
181187

182188
// Determine whether we need to visit this base class at all,
@@ -244,9 +250,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
244250
return FoundPath;
245251
}
246252
} else if (VisitBase) {
247-
CXXRecordDecl *BaseRecord;
253+
CXXRecordDecl *BaseRecord = nullptr;
248254
if (LookupInDependent) {
249-
BaseRecord = nullptr;
250255
const TemplateSpecializationType *TST =
251256
BaseSpec.getType()->getAs<TemplateSpecializationType>();
252257
if (!TST) {
@@ -265,8 +270,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
265270
BaseRecord = nullptr;
266271
}
267272
} else {
268-
BaseRecord = cast<CXXRecordDecl>(
269-
BaseSpec.getType()->castAs<RecordType>()->getDecl());
273+
BaseRecord = cast<CXXRecordDecl>(BaseSpec.getType()->getAsRecordDecl());
270274
}
271275
if (BaseRecord &&
272276
lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {

clang/test/CXX/drs/cwg5xx.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,17 +1178,61 @@ 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;
1188+
};
1189+
};
1190+
1191+
template<typename T> struct G {
1192+
struct B {
1193+
typedef int M;
1194+
struct C {
1195+
typedef void M;
1196+
struct D;
1197+
};
1198+
};
1199+
};
1200+
1201+
template<typename T> struct H {
1202+
template<typename U> struct B {
1203+
typedef int M;
1204+
template<typename F> struct C {
1205+
typedef void M;
1206+
struct D;
1207+
struct P;
1208+
};
11871209
};
11881210
};
11891211

11901212
template<typename T> struct A<T>::B::C : A<T> {
1191-
// FIXME: Should find member of non-dependent base class A<T>.
1213+
M m;
1214+
};
1215+
1216+
template<typename T> struct G<T>::B::C::D : B {
1217+
M m;
1218+
};
1219+
1220+
template<typename T>
1221+
template<typename U>
1222+
template<typename F>
1223+
struct H<T>::B<U>::C<F>::D : B<U> {
1224+
M m;
1225+
};
1226+
1227+
template<typename T> struct A<T>::B::D : A<T*> {
1228+
M m;
1229+
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
1230+
};
1231+
1232+
template<typename T>
1233+
template<typename U>
1234+
template<typename F>
1235+
struct H<T>::B<U>::C<F>::P : B<F> {
11921236
M m;
11931237
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
11941238
};

0 commit comments

Comments
 (0)