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

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 09:57:16 PDT 2024


================
@@ -11723,6 +11764,40 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
       return;
     }
 
+    // Errors in deduction guides from inherited constructors
+    // will present as substitution failures in the mapping
+    // partial specialization, so we show a generic diagnostic
+    // in this case.
+    if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(Templated);
+        DG && DG->getSourceKind() ==
+                  CXXDeductionGuideDecl::SourceKind::InheritedConstructor) {
+      CXXDeductionGuideDecl *Source = DG->getSourceDeductionGuide();
+      assert(Source &&
+             "Inherited constructor deduction guides must have a source");
+      auto DeducedRecordType =
+          QualType(cast<ClassTemplateDecl>(DG->getDeducedTemplate())
+                       ->getTemplatedDecl()
+                       ->getTypeForDecl(),
+                   0);
+      auto InheritedRecordType =
+          QualType(cast<ClassTemplateDecl>(Source->getDeducedTemplate())
+                       ->getTemplatedDecl()
+                       ->getTypeForDecl(),
+                   0);
----------------
mizvekov wrote:

Is the cast to QualType really necessary here? I thought the diagnostic engine could have Type* just fine.
In any case, the last argument should not be necessary.
```suggestion
      auto DeducedRecordType =
          QualType(cast<ClassTemplateDecl>(DG->getDeducedTemplate())
                       ->getTemplatedDecl()
                       ->getTypeForDecl());
      auto InheritedRecordType =
          QualType(cast<ClassTemplateDecl>(Source->getDeducedTemplate())
                       ->getTemplatedDecl()
                       ->getTypeForDecl());
```

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


More information about the cfe-commits mailing list