Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Revert "[clang] Fix CTAD for aggregates for nested template classes" …
Browse files Browse the repository at this point in the history
…(#78541)

Reverts llvm/llvm-project#78387

The added tests are failing on several build bots.
  • Loading branch information
antangelo authored Jan 18, 2024
1 parent 11bf02e commit 7f2408f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 46 deletions.
3 changes: 0 additions & 3 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,6 @@ Bug Fixes to C++ Support
(`#57410 <https://github.com/llvm/llvm-project/issues/57410>`_) and
(`#76604 <https://github.com/llvm/llvm-project/issues/57410>`_)

- Fixes CTAD for aggregates on nested template classes. Fixes:
(`#77599 <https://github.com/llvm/llvm-project/issues/77599>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
9 changes: 1 addition & 8 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10718,14 +10718,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
bool HasAnyDeductionGuide = false;

auto SynthesizeAggrGuide = [&](InitListExpr *ListInit) {
auto *Pattern = Template;
while (Pattern->getInstantiatedFromMemberTemplate()) {
if (Pattern->isMemberSpecialization())
break;
Pattern = Pattern->getInstantiatedFromMemberTemplate();
}

auto *RD = cast<CXXRecordDecl>(Pattern->getTemplatedDecl());
auto *RD = cast<CXXRecordDecl>(Template->getTemplatedDecl());
if (!(RD->getDefinition() && RD->isAggregate()))
return;
QualType Ty = Context.getRecordType(RD);
Expand Down
21 changes: 4 additions & 17 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,23 +2418,16 @@ struct ConvertConstructorToDeductionGuideTransform {
QualType Result = SemaRef.BuildFunctionType(DeducedType, ParamTypes, Loc,
DeductionGuideName, EPI);
TypeSourceInfo *TSI = SemaRef.Context.getTrivialTypeSourceInfo(Result, Loc);
if (NestedPattern)
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
DeductionGuideName);

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

// Build the parameters, needed during deduction / substitution.
SmallVector<ParmVarDecl*, 4> Params;
for (auto T : ParamTypes) {
auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(T, Loc);
if (NestedPattern)
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
DeclarationName());
ParmVarDecl *NewParam =
ParmVarDecl::Create(SemaRef.Context, DC, Loc, Loc, nullptr,
TSI->getType(), TSI, SC_None, nullptr);
ParmVarDecl *NewParam = ParmVarDecl::Create(
SemaRef.Context, DC, Loc, Loc, nullptr, T,
SemaRef.Context.getTrivialTypeSourceInfo(T, Loc), SC_None, nullptr);
NewParam->setScopeInfo(0, Params.size());
FPTL.setParam(Params.size(), NewParam);
Params.push_back(NewParam);
Expand Down Expand Up @@ -2677,14 +2670,8 @@ FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
if (BuildingDeductionGuides.isInvalid())
return nullptr;

ClassTemplateDecl *Pattern =
Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());

auto *DG = cast<FunctionTemplateDecl>(
return cast<FunctionTemplateDecl>(
Transform.buildSimpleDeductionGuide(ParamTypes));
SavedContext.pop();
return DG;
}

void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
Expand Down
19 changes: 1 addition & 18 deletions clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++20 -verify %s
// expected-no-diagnostics

template<class T> struct S {
template<class U> struct N {
Expand Down Expand Up @@ -57,21 +58,3 @@ template<class X> struct requires_clause {
requires_clause<int>::B req(1, 2);
using RC = decltype(req);
using RC = requires_clause<int>::B<int>;

template<typename X> struct nested_init_list {
template<C<X> Y>
struct B { // #INIT_LIST_INNER
X x;
Y y;
};
};

nested_init_list<int>::B nil {1, 2};
using NIL = decltype(nil);
using NIL = nested_init_list<int>::B<int>;

// expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'B'}}
nested_init_list<int>::B nil_invalid {1, ""};
// 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 *]}}
// expected-note@#INIT_LIST_INNER {{candidate function template not viable: requires 1 argument, but 2 were provided}}
// expected-note@#INIT_LIST_INNER {{candidate function template not viable: requires 0 arguments, but 2 were provided}}

0 comments on commit 7f2408f

Please sign in to comment.