The following code produces predictable but odd output. The compiler should either generate a warning for this case or throw away the instantiation of the type upon encountering the better-matching partial specialization, somehow keeping it for code above the given line.
template <typename T> struct A { T o; }; int sizeofa = sizeof(A<int *>); template <typename T> struct A<T *> { T o[5]; }; int newsizeofa = sizeof(A<int *>); int main() { printf("%d, %d, %d\n", sizeofa, sizeof(A<int *>), sizeof(A<double *>)); } The given output is 4, 4, 40, whereas the expected output would be 4, 20, 40. It appears that the specialization is accepted for any type not yet instantiated. Configured with: ../gcc-4.1.2/configure --prefix=/usr --enable-shared --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --with-arch=i486 --target=i486-slackware-linux --host=i486-slackware-linux gcc version 4.1.2 -- Summary: Partial specialization halfway accepted after instantiation Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dascandy at gmail dot com GCC build triplet: i486-slackware-linux GCC host triplet: i486-slackware-linux GCC target triplet: i486-slackware-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32505