Specialized template function with deleted “general” case fails to compile with g++

I don’t know if the following will be enlightening but I found defect report 941: Explicit specialization of deleted function template with status C++11 that states the following (Emphasis Mine):

According to 14.7.3 [temp.expl.spec] paragraph 1, only non-deleted
function templates may be explicitly specialized. There doesn’t
appear to be a compelling need for this restriction, however, and it
could be useful to forbid use of implicitly-instantiated
specializations while still allowing use of explicitly-specialized
versions.

Proposed resolution (February, 2010):

Change 14.7.3 [temp.expl.spec] paragraph 1 as follows:

An explicit specialization of any of the following:

non-deleted function template

class template

non-deleted member function of a class template

static data member of a class template

member class of a class template

member class template of a class or class template

non-deleted member function template of a class or class
template

can be declared…

Now the current state of the draft standard N4527 is 14.7.3 Explicit specialization [temp.expl.spec]:

1 An explicit specialization of any of the following:

(1.1) — function template

(1.2) — class template

(1.3) — variable template

(1.4) — member function of a class template

(1.5) — static data member of a class template

(1.6) — member class of a class template

(1.7) — member enumeration of a class template

(1.8) — member class template of a class or class template

(1.9) — member function template of a class or class template

So I guess:

template<typename T>
void foo() = delete;

template<>
void foo<int>(){}

int main() {
    foo<int>();
    return 0;
}

Is C++11 standard compatible code and should be accepted.

Leave a Comment