A CXXDeductionGuideDecl references its class's template parameters
(rather than cloning them). This causes us to currently call
inheritDefaultTemplateArguments() on the class template parameters
twice, which causes crashes because DefaultArgStorage::setInherited()
should only be called once.
Details
- Reviewers
rsmith dblaikie aaron.ballman
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Serialization/ASTReaderDecl.cpp | ||
---|---|---|
3784–3790 | 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.) |
clang/lib/Serialization/ASTReaderDecl.cpp | ||
---|---|---|
3784–3790 | 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. |
Not sure if you met the same problem with me. In our downstream, we did a workaround like:
if (Context.getLangOpts().CPlusPlusModules && To->getOwningModule() != From->getOwningModule()) return false;
We workarounded the problem by inserting the above checking in inheritDefaultTemplateArgument() in ASTReaderDecl. Hope this helps.
(I understand this is not a good solution)
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.)