Skip to content

Commit ce9eaf0

Browse files
committed
Revert "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (#68379)"
This reverts commit dd0fba1. It fails on nested classes that have both an explicit deduction guide and a constructor that has an argument of the same type as the class (i.e. a copy constructor).
1 parent b0eba8e commit ce9eaf0

File tree

3 files changed

+1
-38
lines changed

3 files changed

+1
-38
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,6 @@ Bug Fixes to C++ Support
516516
rather than prefer the non-templated constructor as specified in
517517
[standard.group]p3.
518518

519-
- Fix a bug where implicit deduction guides are not correctly generated for nested template
520-
classes. Fixes:
521-
(`#46200 <https://github.com/llvm/llvm-project/issues/46200>`_)
522-
(`#57812 <https://github.com/llvm/llvm-project/issues/57812>`_)
523-
524519
Bug Fixes to AST Handling
525520
^^^^^^^^^^^^^^^^^^^^^^^^^
526521
- Fixed an import failure of recursive friend class template.

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,6 @@ struct ConvertConstructorToDeductionGuideTransform {
22502250

22512251
Sema &SemaRef;
22522252
ClassTemplateDecl *Template;
2253-
ClassTemplateDecl *NestedPattern = nullptr;
22542253

22552254
DeclContext *DC = Template->getDeclContext();
22562255
CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2328,8 +2327,6 @@ struct ConvertConstructorToDeductionGuideTransform {
23282327
if (FTD) {
23292328
Args.addOuterTemplateArguments(SubstArgs);
23302329
Args.addOuterRetainedLevel();
2331-
if (NestedPattern)
2332-
Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
23332330
}
23342331

23352332
FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
@@ -2441,17 +2438,10 @@ struct ConvertConstructorToDeductionGuideTransform {
24412438
SmallVector<QualType, 4> ParamTypes;
24422439
const FunctionProtoType *T = TL.getTypePtr();
24432440

2444-
MultiLevelTemplateArgumentList OuterInstantiationArgs;
2445-
if (NestedPattern)
2446-
OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
2447-
24482441
// -- The types of the function parameters are those of the constructor.
24492442
for (auto *OldParam : TL.getParams()) {
24502443
ParmVarDecl *NewParam =
24512444
transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
2452-
if (NestedPattern && NewParam)
2453-
NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
2454-
MaterializedTypedefs);
24552445
if (!NewParam)
24562446
return QualType();
24572447
ParamTypes.push_back(NewParam->getType());
@@ -2657,23 +2647,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
26572647
if (BuildingDeductionGuides.isInvalid())
26582648
return;
26592649

2660-
// If the template is nested, then we need to use the original
2661-
// pattern to iterate over the constructors.
2662-
ClassTemplateDecl *Pattern = Transform.Template;
2663-
while (Pattern->getInstantiatedFromMemberTemplate()) {
2664-
if (Pattern->isMemberSpecialization())
2665-
break;
2666-
Pattern = Pattern->getInstantiatedFromMemberTemplate();
2667-
Transform.NestedPattern = Pattern;
2668-
}
2669-
26702650
// Convert declared constructors into deduction guide templates.
26712651
// FIXME: Skip constructors for which deduction must necessarily fail (those
26722652
// for which some class template parameter without a default argument never
26732653
// appears in a deduced context).
26742654
llvm::SmallPtrSet<NamedDecl *, 8> ProcessedCtors;
26752655
bool AddedAny = false;
2676-
for (NamedDecl *D : LookupConstructors(Pattern->getTemplatedDecl())) {
2656+
for (NamedDecl *D : LookupConstructors(Transform.Primary)) {
26772657
D = D->getUnderlyingDecl();
26782658
if (D->isInvalidDecl() || D->isImplicit())
26792659
continue;

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)