[clang] [Clang] Clarify diagnostic notes for implicitly generated deduction guides (PR #96084)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 06:05:23 PDT 2024


================
@@ -12078,6 +12079,43 @@ static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) {
       << (ES.getExpr() ? ES.getExpr()->getSourceRange() : SourceRange());
 }
 
+static void NoteImplicitDeductionGuide(Sema &S, CXXDeductionGuideDecl *DG) {
+  // We want to always print synthesized deduction guides for type aliases.
+  // They would retain the explicit bit of the corresponding constructor.
+  TemplateDecl *OriginTemplate =
+      DG->getDeclName().getCXXDeductionGuideTemplate();
+  if (!DG->isImplicit() && (!OriginTemplate || !OriginTemplate->isTypeAlias()))
+    return;
+  std::string FunctionProto;
+  llvm::raw_string_ostream OS(FunctionProto);
+  FunctionTemplateDecl *Template = DG->getDescribedFunctionTemplate();
+  if (!Template) {
+    // This also could be an instantiation. Find out the primary template.
+    FunctionDecl *Pattern =
+        DG->getTemplateInstantiationPattern(/*ForDefinition=*/false);
+    if (!Pattern) {
+      // The implicit deduction guide is built on an explicit non-template
+      // deduction guide. Currently, this might be the case only for type
+      // aliases.
+      // FIXME: Add a test once https://github.com/llvm/llvm-project/pull/96686
+      // gets merged.
+      assert(
+          OriginTemplate->isTypeAlias() &&
+          "Only deduction guides for type aliases can have no template Decls");
----------------
hokein wrote:

nit: `non-template implicit deduction guides are only possible for type aliases`

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


More information about the cfe-commits mailing list