This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix assertion when constructor is disabled with partially specialized template.
ClosedPublic

Authored by vsapsai on May 15 2018, 3:31 PM.

Details

Summary

The added test case was triggering assertion

Assertion failed: (!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && "Already set to a class template partial specialization!"), function setInstantiationOf, file clang/include/clang/AST/DeclTemplate.h, line 1825.

It was happening with ClassTemplateSpecializationDecl
enable_if_not_same<int, int>. Because this template is specialized for
equal types not to have a definition, it wasn't instantiated and its
specialization kind remained TSK_Undeclared. And because it was implicit
instantiation, we didn't mark the decl as invalid. So when we try to
find the best matching partial specialization the second time, we hit
the assertion as partial specialization is already set.

Fix by reusing stored partial specialization when available, instead of
looking for the best match every time.

rdar://problem/39524996

Diff Detail

Repository
rL LLVM

Event Timeline

vsapsai created this revision.May 15 2018, 3:31 PM
vsapsai added inline comments.May 15 2018, 3:34 PM
clang/lib/Sema/SemaTemplate.cpp
3873–3881 ↗(On Diff #146943)

Code of interest (will refer to it later).

vsapsai updated this revision to Diff 146944.May 15 2018, 3:39 PM

Potentially, VarTemplateDecl is susceptible to the same bug as
ClassTemplateSpecializationDecl. But I wasn't able to trigger it. And based on
code I've convinced myself that the mentioned early exit in
Sema::CheckVarTemplateId is equivalent to reusing available partial
specialization. So seems like no changes for VarTemplateDecl are required.

rsmith accepted this revision.May 15 2018, 3:49 PM

Looks good. It might be beneficial to do the lookup twice in this case and then issue a diagnostic if the results differ, but given how rarely this is happening, it doesn't really seem worthwhile.

This revision is now accepted and ready to land.May 15 2018, 3:49 PM

Thanks for the quick review, Richard. I'll keep in mind the idea with comparing results of multiple lookups when I work on other partial specialization-related bugs.

This revision was automatically updated to reflect the committed changes.