diff options
| author | Faisal Vali <faisalv@yahoo.com> | 2016-06-14 03:23:15 +0000 |
|---|---|---|
| committer | Faisal Vali <faisalv@yahoo.com> | 2016-06-14 03:23:15 +0000 |
| commit | 81a88beec4f8f4ca4e3dacf652231669c9a947fe (patch) | |
| tree | f1ae12cb5a8e8b764a883331b868dd1eb539f261 /clang/lib/Sema | |
| parent | cccf4f01ada94aeafdef5ee03e9e4418e64b9e28 (diff) | |
| download | bcm5719-llvm-81a88beec4f8f4ca4e3dacf652231669c9a947fe.tar.gz bcm5719-llvm-81a88beec4f8f4ca4e3dacf652231669c9a947fe.zip | |
Fix PR28100 - Allow redeclarations of deleted explicit specializations.
See https://llvm.org/bugs/show_bug.cgi?id=28100.
In r266561 when I implemented allowing explicit specializations of function templates to override deleted status, I mistakenly assumed (and hence introduced a violable assertion) that when an explicit specialization was being declared, the corresponding specialization of the most specialized function template that it would get linked to would always be the one that was implicitly generated - and so if it was marked as 'deleted' it must have inherited it from the primary template and so should be safe to reset its deleted status, and set it to being an explicit specialization. Obviously during redeclaration of a deleted explicit specialization, in order to avoid a recursive reset, we need to check that the previous specialization is not an explicit specialization (instead of assuming and asserting it) and that it hasn't been referenced, and so only then is it safe to reset its 'deleted' status.
All regression tests pass.
Thanks to Zhendong Su for reporting the bug and David Majnemer for tracking it to my commit r266561, and promptly bringing it to my attention.
llvm-svn: 272631
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 2ea242fc956..58da453e2a8 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6989,12 +6989,20 @@ bool Sema::CheckFunctionTemplateSpecialization( // Mark the prior declaration as an explicit specialization, so that later // clients know that this is an explicit specialization. if (!isFriend) { - // Explicit specializations do not inherit '=delete' from their primary
- // function template.
- if (Specialization->isDeleted()) {
- assert(!SpecInfo->isExplicitSpecialization());
- assert(Specialization->getCanonicalDecl() == Specialization);
- Specialization->setDeletedAsWritten(false);
+ // Since explicit specializations do not inherit '=delete' from their + // primary function template - check if the 'specialization' that was + // implicitly generated (during template argument deduction for partial + // ordering) from the most specialized of all the function templates that + // 'FD' could have been specializing, has a 'deleted' definition. If so, + // first check that it was implicitly generated during template argument + // deduction by making sure it wasn't referenced, and then reset the deleted + // flag to not-deleted, so that we can inherit that information from 'FD'. + if (Specialization->isDeleted() && !SpecInfo->isExplicitSpecialization() && + !Specialization->getCanonicalDecl()->isReferenced()) { + assert( + Specialization->getCanonicalDecl() == Specialization && + "This must be the only existing declaration of this specialization"); + Specialization->setDeletedAsWritten(false); } SpecInfo->setTemplateSpecializationKind(TSK_ExplicitSpecialization); MarkUnusedFileScopedDecl(Specialization); |

