[PATCH] D80743: (PR46111) Desugar Elaborated types in Deduction Guides.

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 28 10:56:21 PDT 2020


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80743.266940.patch
Type: text/x-patch
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200528/22788f7f/attachment.bin>


More information about the cfe-commits mailing list