[Sema] Fix assertion when constructor is disabled with partially specialized template.
authorVolodymyr Sapsai <vsapsai@apple.com>
Wed, 16 May 2018 18:28:58 +0000 (18:28 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Wed, 16 May 2018 18:28:58 +0000 (18:28 +0000)
commit9b973483ed3bec6d0224cd75dd95bc9cc9b7b0a5
tree44ea27121dc7179ebab7f6e3e6effce5d328ce87
parentb24957e22a965535d34f8f987c8b4b6ccfcd5f69
[Sema] Fix assertion when constructor is disabled with partially specialized template.

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

Reviewers: rsmith, arphaman

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D46909

llvm-svn: 332509
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/partial-spec-instantiate.cpp