[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 18:54:20 PDT 2024


================
@@ -1426,6 +1727,34 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   if (!AddedAny)
     Transform.buildSimpleDeductionGuide(std::nullopt);
 
+  // FIXME: Handle explicit deduction guides from inherited constructors
+  // when the base deduction guides are declared after this has first run
+  if (getLangOpts().CPlusPlus23 &&
+      Pattern->getTemplatedDecl()->hasDefinition()) {
+    unsigned BaseIdx = 0;
+    for (const auto &Base : Pattern->getTemplatedDecl()->bases()) {
+      ++BaseIdx;
+      if (!Base.getType()->isDependentType())
----------------
antangelo wrote:

I've updated the method of looking up inherited constructors to use the `UnresolvedUsingValueDecl`s on the pattern directly instead of finding them through the list of bases. It will now create generic deduction guides for `B<T2>` in your example, which will work in the case of `B<int>` but fail after instantiation if `T2` is not `int`.

https://github.com/llvm/llvm-project/pull/98788


More information about the cfe-commits mailing list