[clang] Revert "[clang] Fix CTAD for aggregates for nested template classes" (PR #78541)

2024-01-17 Thread via cfe-commits

https://github.com/antangelo closed 
https://github.com/llvm/llvm-project/pull/78541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang] Fix CTAD for aggregates for nested template classes" (PR #78541)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (antangelo)


Changes

Reverts llvm/llvm-project#78387

The added tests are failing on several build bots.

---
Full diff: https://github.com/llvm/llvm-project/pull/78541.diff


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (-3) 
- (modified) clang/lib/Sema/SemaInit.cpp (+1-8) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+4-17) 
- (modified) clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
(+1-18) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d70d6dfd5df9fe3..cf52c1e66b91b42 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -972,9 +972,6 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
-- Fixes CTAD for aggregates on nested template classes. Fixes:
-  (`#77599 `_)
-
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 48235941f62aa23..408ee5f775804b6 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -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(Pattern->getTemplatedDecl());
+  auto *RD = cast(Template->getTemplatedDecl());
   if (!(RD->getDefinition() && RD->isAggregate()))
 return;
   QualType Ty = Context.getRecordType(RD);
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 839d508b911f063..0655d3633520676 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2418,9 +2418,6 @@ 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();
@@ -2428,13 +2425,9 @@ struct ConvertConstructorToDeductionGuideTransform {
 // Build the parameters, needed during deduction / substitution.
 SmallVector 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);
@@ -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(
+  return cast(
   Transform.buildSimpleDeductionGuide(ParamTypes));
-  SavedContext.pop();
-  return DG;
 }
 
 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
diff --git a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
index f3af6e8d6c17da0..c44ec6918c7afb1 100644
--- a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
+++ b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
 
 template struct S {
 template struct N {
@@ -57,21 +58,3 @@ template struct requires_clause {
 requires_clause::B req(1, 2);
 using RC = decltype(req);
 using RC = requires_clause::B;
-
-template struct nested_init_list {
-template Y>
-struct B { // #INIT_LIST_INNER
-X x;
-Y y;
-};
-};
-
-nested_init_list::B nil {1, 2};
-using NIL = decltype(nil);
-using NIL = nested_init_list::B;
-
-// expected-error@+1 {{no v

[clang] Revert "[clang] Fix CTAD for aggregates for nested template classes" (PR #78541)

2024-01-17 Thread via cfe-commits

https://github.com/antangelo created 
https://github.com/llvm/llvm-project/pull/78541

Reverts llvm/llvm-project#78387

The added tests are failing on several build bots.

>From d534c2333cdba7749f22fd631ec8a73a13c2405b Mon Sep 17 00:00:00 2001
From: antangelo 
Date: Wed, 17 Jan 2024 22:55:55 -0500
Subject: [PATCH] Revert "[clang] Fix CTAD for aggregates for nested template
 classes"

---
 clang/docs/ReleaseNotes.rst   |  3 ---
 clang/lib/Sema/SemaInit.cpp   |  9 +---
 clang/lib/Sema/SemaTemplate.cpp   | 21 ---
 .../nested-implicit-deduction-guides.cpp  | 19 +
 4 files changed, 6 insertions(+), 46 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d70d6dfd5df9fe3..cf52c1e66b91b42 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -972,9 +972,6 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
-- Fixes CTAD for aggregates on nested template classes. Fixes:
-  (`#77599 `_)
-
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 48235941f62aa23..408ee5f775804b6 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -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(Pattern->getTemplatedDecl());
+  auto *RD = cast(Template->getTemplatedDecl());
   if (!(RD->getDefinition() && RD->isAggregate()))
 return;
   QualType Ty = Context.getRecordType(RD);
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 839d508b911f063..0655d3633520676 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2418,9 +2418,6 @@ 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();
@@ -2428,13 +2425,9 @@ struct ConvertConstructorToDeductionGuideTransform {
 // Build the parameters, needed during deduction / substitution.
 SmallVector 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);
@@ -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(
+  return cast(
   Transform.buildSimpleDeductionGuide(ParamTypes));
-  SavedContext.pop();
-  return DG;
 }
 
 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
diff --git a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
index f3af6e8d6c17da0..c44ec6918c7afb1 100644
--- a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
+++ b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
 
 template struct S {
 template struct N {
@@ -57,21 +58,3 @@ template struct requires_clause {
 requires_clause::B req(1, 2);
 using RC = decltype(req);
 using RC = requires_clause::B;
-
-template struct nested_init_list {
-template Y>
-stru