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

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 10 17:13:37 PST 2022


aeubanks 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);
+  }
----------------
rsmith wrote:
> 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.)
I tried https://reviews.llvm.org/D116983 and it still doesn't fix this issue, although I'm having trouble understanding the Clang AST and the decl chains.
How would you check that the template parameter is owned by this template?


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