Skip to content

Commit 57f42a8

Browse files
committed
Revert "[clang] Substitute alias templates from correct context (#75069)"
This reverts commit dbf67ea. It caused spurious "out-of-line definition of 'operator=' does not match any declaration in" error. #75069 (comment)
1 parent 47b4bbf commit 57f42a8

File tree

6 files changed

+10
-103
lines changed

6 files changed

+10
-103
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,6 @@ Bug Fixes in This Version
685685
(`#62157 <https://github.com/llvm/llvm-project/issues/62157>`_) and
686686
(`#64885 <https://github.com/llvm/llvm-project/issues/64885>`_) and
687687
(`#65568 <https://github.com/llvm/llvm-project/issues/65568>`_)
688-
- Fixed false positive error emitted when templated alias inside a class
689-
used private members of the same class.
690-
Fixes (`#41693 <https://github.com/llvm/llvm-project/issues/41693>`_)
691688

692689
Bug Fixes to Compiler Builtins
693690
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8737,7 +8737,7 @@ class Sema final {
87378737
SourceLocation IILoc,
87388738
bool DeducedTSTContext = true);
87398739

8740-
bool RebuildingTypesInCurrentInstantiation = false;
8740+
87418741
TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
87428742
SourceLocation Loc,
87438743
DeclarationName Name);

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 4 additions & 20 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 (auto *ICNT = dyn_cast<InjectedClassNameType>(Ty))
57-
return ICNT->getDecl();
58-
59-
return nullptr;
40+
} else if (isa<InjectedClassNameType>(Ty))
41+
return cast<InjectedClassNameType>(Ty)->getDecl();
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "llvm/ADT/SmallBitVector.h"
4040
#include "llvm/ADT/SmallString.h"
4141
#include "llvm/ADT/StringExtras.h"
42-
#include "llvm/Support/SaveAndRestore.h"
4342

4443
#include <iterator>
4544
#include <optional>
@@ -3991,14 +3990,9 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
39913990
if (Inst.isInvalid())
39923991
return QualType();
39933992

3994-
{
3995-
Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
3996-
if (RebuildingTypesInCurrentInstantiation)
3997-
SavedContext.pop();
3998-
CanonType =
3999-
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4000-
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
4001-
}
3993+
CanonType = SubstType(Pattern->getUnderlyingType(),
3994+
TemplateArgLists, AliasTemplate->getLocation(),
3995+
AliasTemplate->getDeclName());
40023996
if (CanonType.isNull()) {
40033997
// If this was enable_if and we failed to find the nested type
40043998
// within enable_if in a SFINAE context, dig out the specific
@@ -11398,8 +11392,6 @@ TypeSourceInfo *Sema::RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
1139811392
if (!T || !T->getType()->isInstantiationDependentType())
1139911393
return T;
1140011394

11401-
llvm::SaveAndRestore DisableContextSwitchForTypeAliases(
11402-
RebuildingTypesInCurrentInstantiation, true);
1140311395
CurrentInstantiationRebuilder Rebuilder(*this, Loc, Name);
1140411396
return Rebuilder.TransformType(T);
1140511397
}

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 & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -192,68 +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-
// No errors when a type alias defined in a class or a friend of a class
198-
// accesses private members of the same class.
199-
struct S {
200-
private:
201-
template <typename> static constexpr void Impl() {}
202-
203-
public:
204-
template <typename X> using U = decltype(Impl<X>());
205-
};
206-
207-
using X = S::U<void>;
208-
struct Y {
209-
private:
210-
static constexpr int x=0;
211-
212-
template <typename>
213-
static constexpr int y=0;
214-
215-
template <typename>
216-
static constexpr int foo();
217-
218-
public:
219-
template <typename U>
220-
using bar1 = decltype(foo<U>());
221-
using bar2 = decltype(x);
222-
template <typename U>
223-
using bar3 = decltype(y<U>);
224-
};
225-
226-
227-
using type1 = Y::bar1<float>;
228-
using type2 = Y::bar2;
229-
using type3 = Y::bar3<float>;
230-
231-
struct theFriend{
232-
template<class T>
233-
using theAlias = decltype(&T::i);
234-
};
235-
236-
class theC{
237-
int i;
238-
public:
239-
friend struct theFriend;
240-
};
241-
242-
int foo(){
243-
(void)sizeof(theFriend::theAlias<theC>);
244-
}
245-
246-
// Test case that regressed with the first iteration of the fix for GH41693.
247-
template <typename T> class SP {
248-
T* data;
249-
};
250-
251-
template <typename T> class A {
252-
static SP<A> foo();
253-
};
254-
255-
template<typename T> using TRet = SP<A<T>>;
256-
257-
template<typename T> TRet<T> A<T>::foo() { return TRet<T>{};};
258-
259-
}

0 commit comments

Comments
 (0)