erichkeane created this revision.
erichkeane added reviewers: rsmith, rjmccall.
erichkeane added a comment.

I hope that @rsmith pays particular attention here for me, I'm unable to come 
up with any cases where this isn't sufficient/breaks other things, but I also 
don't feel like I know deduction guides well enough to claim that I don't break 
anything :)  All the lit tests pass, for what its worth.


As reported in PR46111, implicit instantiation of a deduction guide
causes us to have an elaborated type as the parameter, rather than the
dependent type.  This patch makes sure we desugar the elaborated types
when generating the deduction guides.


Repository:
  rC Clang

https://reviews.llvm.org/D80743

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/deduction-guides.cpp


Index: clang/test/AST/deduction-guides.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/deduction-guides.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only %s -ast-dump -std=c++17 | FileCheck %s
+
+namespace PR46111 {
+template <typename>
+struct S;
+
+template <typename T>
+struct HasDeductionGuide {
+  typedef PR46111::S<T> STy;
+  HasDeductionGuide(typename STy::Child);
+  };
+
+// This causes deduction guides to be generated for all constructors.
+HasDeductionGuide() ->HasDeductionGuide<int>;
+
+// The parameter to this one shouldn't be an elaborated type.
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for 
HasDeductionGuide> 'auto (typename S<T>::Child) -> HasDeductionGuide<T>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for 
HasDeductionGuide> 'auto (HasDeductionGuide<T>) -> HasDeductionGuide<T>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for 
HasDeductionGuide> 'auto () -> HasDeductionGuide<int>'
+} // namespace PR46111
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1958,6 +1958,10 @@
         TLB,
         TL.getTypedefNameDecl()->getTypeSourceInfo()->getTypeLoc());
   }
+
+  QualType TransformElaboratedType(TypeLocBuilder &TLB, ElaboratedTypeLoc TL) {
+    return TransformType(TLB, TL.getNamedTypeLoc());
+  }
 };
 
 /// Transform to convert portions of a constructor declaration into the


Index: clang/test/AST/deduction-guides.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/deduction-guides.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only %s -ast-dump -std=c++17 | FileCheck %s
+
+namespace PR46111 {
+template <typename>
+struct S;
+
+template <typename T>
+struct HasDeductionGuide {
+  typedef PR46111::S<T> STy;
+  HasDeductionGuide(typename STy::Child);
+  };
+
+// This causes deduction guides to be generated for all constructors.
+HasDeductionGuide() ->HasDeductionGuide<int>;
+
+// The parameter to this one shouldn't be an elaborated type.
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuide> 'auto (typename S<T>::Child) -> HasDeductionGuide<T>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuide> 'auto (HasDeductionGuide<T>) -> HasDeductionGuide<T>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuide> 'auto () -> HasDeductionGuide<int>'
+} // namespace PR46111
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1958,6 +1958,10 @@
         TLB,
         TL.getTypedefNameDecl()->getTypeSourceInfo()->getTypeLoc());
   }
+
+  QualType TransformElaboratedType(TypeLocBuilder &TLB, ElaboratedTypeLoc TL) {
+    return TransformType(TLB, TL.getNamedTypeLoc());
+  }
 };
 
 /// Transform to convert portions of a constructor declaration into the
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to