Skip to content

Commit 7f2408f

Browse files
authored
Revert "[clang] Fix CTAD for aggregates for nested template classes" (#78541)
Reverts #78387 The added tests are failing on several build bots.
1 parent 11bf02e commit 7f2408f

File tree

4 files changed

+6
-46
lines changed

4 files changed

+6
-46
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,6 @@ Bug Fixes to C++ Support
972972
(`#57410 <https://github.com/llvm/llvm-project/issues/57410>`_) and
973973
(`#76604 <https://github.com/llvm/llvm-project/issues/57410>`_)
974974

975-
- Fixes CTAD for aggregates on nested template classes. Fixes:
976-
(`#77599 <https://github.com/llvm/llvm-project/issues/77599>`_)
977-
978975
Bug Fixes to AST Handling
979976
^^^^^^^^^^^^^^^^^^^^^^^^^
980977
- Fixed an import failure of recursive friend class template.

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10718,14 +10718,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1071810718
bool HasAnyDeductionGuide = false;
1071910719

1072010720
auto SynthesizeAggrGuide = [&](InitListExpr *ListInit) {
10721-
auto *Pattern = Template;
10722-
while (Pattern->getInstantiatedFromMemberTemplate()) {
10723-
if (Pattern->isMemberSpecialization())
10724-
break;
10725-
Pattern = Pattern->getInstantiatedFromMemberTemplate();
10726-
}
10727-
10728-
auto *RD = cast<CXXRecordDecl>(Pattern->getTemplatedDecl());
10721+
auto *RD = cast<CXXRecordDecl>(Template->getTemplatedDecl());
1072910722
if (!(RD->getDefinition() && RD->isAggregate()))
1073010723
return;
1073110724
QualType Ty = Context.getRecordType(RD);

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,23 +2418,16 @@ struct ConvertConstructorToDeductionGuideTransform {
24182418
QualType Result = SemaRef.BuildFunctionType(DeducedType, ParamTypes, Loc,
24192419
DeductionGuideName, EPI);
24202420
TypeSourceInfo *TSI = SemaRef.Context.getTrivialTypeSourceInfo(Result, Loc);
2421-
if (NestedPattern)
2422-
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
2423-
DeductionGuideName);
24242421

24252422
FunctionProtoTypeLoc FPTL =
24262423
TSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
24272424

24282425
// Build the parameters, needed during deduction / substitution.
24292426
SmallVector<ParmVarDecl*, 4> Params;
24302427
for (auto T : ParamTypes) {
2431-
auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(T, Loc);
2432-
if (NestedPattern)
2433-
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
2434-
DeclarationName());
2435-
ParmVarDecl *NewParam =
2436-
ParmVarDecl::Create(SemaRef.Context, DC, Loc, Loc, nullptr,
2437-
TSI->getType(), TSI, SC_None, nullptr);
2428+
ParmVarDecl *NewParam = ParmVarDecl::Create(
2429+
SemaRef.Context, DC, Loc, Loc, nullptr, T,
2430+
SemaRef.Context.getTrivialTypeSourceInfo(T, Loc), SC_None, nullptr);
24382431
NewParam->setScopeInfo(0, Params.size());
24392432
FPTL.setParam(Params.size(), NewParam);
24402433
Params.push_back(NewParam);
@@ -2677,14 +2670,8 @@ FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
26772670
if (BuildingDeductionGuides.isInvalid())
26782671
return nullptr;
26792672

2680-
ClassTemplateDecl *Pattern =
2681-
Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
2682-
ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
2683-
2684-
auto *DG = cast<FunctionTemplateDecl>(
2673+
return cast<FunctionTemplateDecl>(
26852674
Transform.buildSimpleDeductionGuide(ParamTypes));
2686-
SavedContext.pop();
2687-
return DG;
26882675
}
26892676

26902677
void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,

clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++20 -verify %s
2+
// expected-no-diagnostics
23

34
template<class T> struct S {
45
template<class U> struct N {
@@ -57,21 +58,3 @@ template<class X> struct requires_clause {
5758
requires_clause<int>::B req(1, 2);
5859
using RC = decltype(req);
5960
using RC = requires_clause<int>::B<int>;
60-
61-
template<typename X> struct nested_init_list {
62-
template<C<X> Y>
63-
struct B { // #INIT_LIST_INNER
64-
X x;
65-
Y y;
66-
};
67-
};
68-
69-
nested_init_list<int>::B nil {1, 2};
70-
using NIL = decltype(nil);
71-
using NIL = nested_init_list<int>::B<int>;
72-
73-
// expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'B'}}
74-
nested_init_list<int>::B nil_invalid {1, ""};
75-
// expected-note@#INIT_LIST_INNER {{candidate template ignored: substitution failure [with Y = const char *]: constraints not satisfied for class template 'B' [with Y = const char *]}}
76-
// expected-note@#INIT_LIST_INNER {{candidate function template not viable: requires 1 argument, but 2 were provided}}
77-
// expected-note@#INIT_LIST_INNER {{candidate function template not viable: requires 0 arguments, but 2 were provided}}

0 commit comments

Comments
 (0)