(undocumented?) difference between gcc 4.6 and 4.7 (C++ implicit template instantiation)

Christoph Groth cwg@falma.de
Tue Aug 28 17:24:00 GMT 2012


Dear GCC experts,

While developing a Python extension using CPython's C API in C++ I've
encountered a situation where a program compiles with GCC 4.7.1 but does
not compile with 4.6.3.  I have attached a minimal program demonstrating
the problem.  As a workaround, adding a explicit instantiation makes the
program also compile under GCC 4.6.

I've been unable to find a description of this issue in any changelog.
Actually, I wonder whether the behavior of 4.6 or that of 4.7 is the
correct one with regard to the C++ language standard.

Is this a known issue which has been fixed in 4.7, or rather a
regression from 4.6?



// Compile with: g++ test.cc

typedef void *(*Func)(void *);

template <typename T>
class Class {
public:
    static Func hoho;
};

template <typename T>
void *something(Class<T> *self)
{
}

// The following line makes it compile under GCC 4.6
// template void *something(Class<long>*);

template <typename T>
Func Class<T>::hoho = (Func)something<T>;

// Explicit instantiation.  This does instantiate something<long>
// under GCC 4.7 but not under GCC 4.6.
template class Class<long>;

int main()
{
    Class<long>::hoho(0);
}



More information about the Gcc-help mailing list