This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Incorrect (?) template specialization results when compiling with -O3


No, the specializations are not visible from the caller. The <int>
specialization is only in the .cpp file.

What's really nasty about this is that now the header file that defines
the template function has to declare all the specializations. However,
some of these specializations are user-defined types. For some cases a
simple forward-declaration of the data type will suffice, but it gets
more complicated when the user-defined type is something like an
inner-class. As far as I know, there's no way to forward declare both
the outer- and -inner classes. Therefore the header file that defines
the template function has to include the header file that defines the
user-defined type, which easily leads to a circular dependency.

The alternative is that the header file for the user-defined type has to
declare the template specialization. At the moment that's the only
solution I've found that seems to work reliably, but it's ugly!

On Fri, 10 Jul 2009 06:46 -0500, "Andrew Bell"
<andrew.bell.ia@gmail.com> wrote:
> But int your example, isn't the <int> specialization visible at the
> point the call is made - even if it is through the header file?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]