Skip to content

Commit f7dc1d0

Browse files
authored
Revert "[Clang] Fix name lookup for dependent bases (#114978)" (#117727)
This reverts commit 4866447 as requested by the commit author. Buildbots fail: * https://lab.llvm.org/buildbot/#/builders/164/builds/4945 * https://lab.llvm.org/buildbot/#/builders/52/builds/4021
1 parent 80df56e commit f7dc1d0

File tree

4 files changed

+9
-62
lines changed

4 files changed

+9
-62
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ Resolutions to C++ Defect Reports
279279
by default.
280280
(`CWG2521: User-defined literals and reserved identifiers <https://cplusplus.github.io/CWG/issues/2521.html>`_).
281281

282-
- Fix name lookup for a dependent base class that is the current instantiation.
283-
(`CWG591: When a dependent base class is the current instantiation <https://cplusplus.github.io/CWG/issues/591.html>`_).
284-
285282
C Language Changes
286283
------------------
287284

clang/lib/AST/CXXInheritance.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback BaseMatches) const {
134134
return false;
135135

136136
CXXRecordDecl *Base =
137-
cast_if_present<CXXRecordDecl>(Ty->getDecl()->getDefinition());
137+
cast_or_null<CXXRecordDecl>(Ty->getDecl()->getDefinition());
138138
if (!Base ||
139139
(Base->isDependentContext() &&
140140
!Base->isCurrentInstantiation(Record))) {
@@ -169,21 +169,13 @@ 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-
}
179172
// C++ [temp.dep]p3:
180173
// In the definition of a class template or a member of a class template,
181174
// if a base class of the class template depends on a template-parameter,
182175
// the base class scope is not examined during unqualified name lookup
183176
// either at the point of definition of the class template or member or
184177
// during an instantiation of the class tem- plate or member.
185-
if (!LookupInDependent &&
186-
(BaseType->isDependentType() && !isCurrentInstantiation))
178+
if (!LookupInDependent && BaseType->isDependentType())
187179
continue;
188180

189181
// Determine whether we need to visit this base class at all,
@@ -251,8 +243,9 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
251243
return FoundPath;
252244
}
253245
} else if (VisitBase) {
254-
CXXRecordDecl *BaseRecord = nullptr;
246+
CXXRecordDecl *BaseRecord;
255247
if (LookupInDependent) {
248+
BaseRecord = nullptr;
256249
const TemplateSpecializationType *TST =
257250
BaseSpec.getType()->getAs<TemplateSpecializationType>();
258251
if (!TST) {
@@ -271,7 +264,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
271264
BaseRecord = nullptr;
272265
}
273266
} else {
274-
BaseRecord = cast<CXXRecordDecl>(BaseSpec.getType()->getAsRecordDecl());
267+
BaseRecord = cast<CXXRecordDecl>(
268+
BaseSpec.getType()->castAs<RecordType>()->getDecl());
275269
}
276270
if (BaseRecord &&
277271
lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {

clang/test/CXX/drs/cwg5xx.cpp

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,61 +1178,17 @@ 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: yes
1181+
namespace cwg591 { // cwg591: no
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-
};
12091187
};
12101188
};
12111189

12121190
template<typename T> struct A<T>::B::C : 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> {
1191+
// FIXME: Should find member of non-dependent base class A<T>.
12361192
M m;
12371193
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
12381194
};

clang/www/cxx_dr_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
35993599
<td><a href="https://cplusplus.github.io/CWG/issues/591.html">591</a></td>
36003600
<td>CD4</td>
36013601
<td>When a dependent base class is the current instantiation</td>
3602-
<td class="none" align="center">Yes</td>
3602+
<td class="none" align="center">No</td>
36033603
</tr>
36043604
<tr id="592">
36053605
<td><a href="https://cplusplus.github.io/CWG/issues/592.html">592</a></td>

0 commit comments

Comments
 (0)