[cfe-commits] [patch] rejects-valid: explicit specialization of redeclaration of a deleted function template

David Blaikie dblaikie at gmail.com
Tue Jun 26 11:37:37 PDT 2012


The following code is (incorrectly) rejected:

template<typename> void foo() = delete;
template<typename> void foo(); // remove this line & the error is not produced
template void foo<int>(); // "explicit instantiation of undefined
function template 'foo'"

There's a few ways to fix this & I'm not sure which one is preferred:

1) Correct the first 3 lines of
TemplateDeclInstantiator::InitFunctionInstantiation:

  if (Tmpl->isDeletedAsWritten())
    New->setDeletedAsWritten()

to

  if (Tmpl->isDeleted())
    New->setDeletedAsWritten()

In this way, the implicit specialization will always correctly reflect
the fact that it's deleted and intervening redeclarations won't
confuse/break this invariant.

2) Remove the first 3 lines of
TemplateDeclInstantiator::InitFunctionInstantiator. Since we're only
instantiating the declaration, one could argue that it shouldn't be
prematurely turned into a definition just because it's deleted
(conversely: = delete has to be the first declaration, so having a
declaration that isn't an = delete definition is also a bit
questionable). In this case we'd need to also fix line
SemaTemplateInstantiateDecl:2572 (SemaInstantiateFunctionDefinition)
to test "IsDefined()" not just "IsDefaulted()". If that's the way
we're going to deal with deleted templates, we could go & change
SemaTemplateInstantiateDecl.cpp:1537 for member functions to match
this too (hmm, actually removing the setDefaulted/setDeleted calls
does cause at least one test to fail, so I'd have to poke around more
if I was going to do that)

Any thoughts/preferences?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2-remove.diff
Type: application/octet-stream
Size: 2389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120626/38262dd8/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-modify.diff
Type: application/octet-stream
Size: 1371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120626/38262dd8/attachment-0001.obj>


More information about the cfe-commits mailing list