[PATCH] D114908: [clang] Don't call inheritDefaultTemplateArguments() on CXXDeductionGuideDecl's template parameters

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 7 12:51:06 PST 2022


rsmith added inline comments.


================
Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:3784-3790
+  if (auto *TD = dyn_cast<TemplateDecl>(D)) {
+    // CXXDeductionGuideDecls reference the class template parameters so we need
+    // to make sure not to call this twice on the same template parameters.
+    if (!isa<CXXDeductionGuideDecl>(TD->getTemplatedDecl()))
+      inheritDefaultTemplateArguments(Reader.getContext(),
+                                      cast<TemplateDecl>(Previous), TD);
+  }
----------------
An implicit deduction guide can get template parameters from both the class template and the constructor template. The ones from the class template are not copied and owned by the deduction guide, but the ones from the constructor template are. So I think we may need to do this for *some* of the template parameters and not others. Perhaps we could check to see if the template parameter is actually owned by this template and skip updating it if not.

(Alternatively, I think it'd be fine, and probably simpler and cleaner, to make implicit deduction guide generation always clone the template parameters of the class template. The confusion caused by having the template parameters appear in the "wrong" template is probably not justified by the time / memory savings.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114908/new/

https://reviews.llvm.org/D114908



More information about the cfe-commits mailing list