Skip to content

Commit 565ddde

Browse files
committed
Revert "[clang] Substitute alias templates from correct context (#74335)"
It was reported in the PR that commit caused clang giving errors for code previously considered valid. This reverts commit 6b1aa31.
1 parent 0365677 commit 565ddde

File tree

5 files changed

+8
-85
lines changed

5 files changed

+8
-85
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,6 @@ Bug Fixes in This Version
658658
Fixes (`#64467 <https://github.com/llvm/llvm-project/issues/64467>`_)
659659
- Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are known non-negative constants.
660660
Fixes (`#18763 <https://github.com/llvm/llvm-project/issues/18763>`_)
661-
- Fixed false positive error emitted when templated alias inside a class
662-
used private members of the same class.
663-
Fixes (`#41693 <https://github.com/llvm/llvm-project/issues/41693>`_)
664661

665662
Bug Fixes to Compiler Builtins
666663
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,17 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
3030
return nullptr;
3131

3232
const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
33-
if (isa<TemplateSpecializationType>(Ty)) {
34-
if (auto *Record = dyn_cast<CXXRecordDecl>(CurContext)) {
35-
if (isa<ClassTemplatePartialSpecializationDecl>(Record) ||
36-
Record->getDescribedClassTemplate()) {
37-
const Type *ICNT = Record->getTypeForDecl();
38-
QualType Injected =
39-
cast<InjectedClassNameType>(ICNT)->getInjectedSpecializationType();
40-
41-
if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
42-
return Record;
43-
}
44-
}
45-
}
46-
4733
if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
4834
CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
4935
if (!Record->isDependentContext() ||
5036
Record->isCurrentInstantiation(CurContext))
5137
return Record;
5238

5339
return nullptr;
54-
}
55-
56-
if (isa<InjectedClassNameType>(Ty))
40+
} else if (isa<InjectedClassNameType>(Ty))
5741
return cast<InjectedClassNameType>(Ty)->getDecl();
58-
59-
return nullptr;
42+
else
43+
return nullptr;
6044
}
6145

6246
/// Compute the DeclContext that is associated with the given type.

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,16 +3990,9 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
39903990
if (Inst.isInvalid())
39913991
return QualType();
39923992

3993-
{
3994-
bool ForLambdaCallOperator = false;
3995-
if (const auto *Rec = dyn_cast<CXXRecordDecl>(Pattern->getDeclContext()))
3996-
ForLambdaCallOperator = Rec->isLambda();
3997-
Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext(),
3998-
!ForLambdaCallOperator);
3999-
CanonType =
4000-
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4001-
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
4002-
}
3993+
CanonType = SubstType(Pattern->getUnderlyingType(),
3994+
TemplateArgLists, AliasTemplate->getLocation(),
3995+
AliasTemplate->getDeclName());
40033996
if (CanonType.isNull()) {
40043997
// If this was enable_if and we failed to find the nested type
40053998
// within enable_if in a SFINAE context, dig out the specific

clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
// The example given in the standard (this is rejected for other reasons anyway).
44
template<class T> struct A;
5-
template<class T> using B = typename A<T>::U; // expected-error {{no type named 'U' in 'A<short>'}}
6-
// expected-note@-1 {{in instantiation of template class 'A<short>' requested here}}
5+
template<class T> using B = typename A<T>::U; // expected-error {{no type named 'U' in 'A<T>'}}
76
template<class T> struct A {
87
typedef B<T> U; // expected-note {{in instantiation of template type alias 'B' requested here}}
98
};
10-
B<short> b; // expected-note {{in instantiation of template type alias 'B' requested here}}
9+
B<short> b;
1110

1211
template<typename T> using U = int;
1312

clang/test/SemaCXX/alias-template.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -192,53 +192,3 @@ int g = sfinae_me<int>(); // expected-error{{no matching function for call to 's
192192
namespace NullExceptionDecl {
193193
template<int... I> auto get = []() { try { } catch(...) {}; return I; }; // expected-error{{initializer contains unexpanded parameter pack 'I'}}
194194
}
195-
196-
namespace GH41693 {
197-
struct S {
198-
private:
199-
template <typename> static constexpr void Impl() {}
200-
201-
public:
202-
template <typename X> using U = decltype(Impl<X>());
203-
};
204-
205-
using X = S::U<void>;
206-
struct Y {
207-
private:
208-
static constexpr int x=0;
209-
210-
template <typename>
211-
static constexpr int y=0;
212-
213-
template <typename>
214-
static constexpr int foo();
215-
216-
public:
217-
template <typename U>
218-
using bar1 = decltype(foo<U>());
219-
using bar2 = decltype(x);
220-
template <typename U>
221-
using bar3 = decltype(y<U>);
222-
};
223-
224-
225-
using type1 = Y::bar1<float>;
226-
using type2 = Y::bar2;
227-
using type3 = Y::bar3<float>;
228-
229-
struct theFriend{
230-
template<class T>
231-
using theAlias = decltype(&T::i);
232-
};
233-
234-
class theC{
235-
int i;
236-
public:
237-
friend struct theFriend;
238-
};
239-
240-
int foo(){
241-
(void)sizeof(theFriend::theAlias<theC>);
242-
}
243-
244-
}

0 commit comments

Comments
 (0)