problem with template specialization in 1.1.2
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Wed Mar 31 23:54:00 GMT 1999
> But there is no definition (as in a general purpose template) for
> foo<TYPE>() in scope at all! There is a declaration of foo<TYPE>(),
> but no definition. So how can foo<int>() have been instantiated
> if there was nothing to instantiate it from?
Ah yes. That of course is an error; a template definition must be
available when the template is instantiated (unless the template is
exported). It seems g++ didn't detect this.
> I'll be the first to admit my knowledge of C++ is hardly exhaustive,
> but this totally doesn't make sense to me. Moreover this example
> has worked with the other C++ compilers I've tried: Microsoft's
> and TenDRA.
I believe this error does not need to be detected. A compiler is free
to perform the instantiation at any time after the 'point of
instantiation'; in particular, implementations are permitted to
instantiate at the end of the translation unit.
If the definition of one of the non-dependent names changes after the
point-of-instantiation, the program is ill-formed. However, no
diagnostic is required, so VC++ and TenDRA could still be right.
I haven't researched the standard on that (right now), so I might be
wrong. Unless somebody else tells us what the matter is, I propose to
either change your code, or to take this to comp.std.c++, and come
back if you've got some clarification there. I believe Stroustrup also
has a section on that issue.
Regards,
Martin
More information about the Gcc-bugs
mailing list