[GiNaC-list] Problem using a user-defined class on Mac OS X.
Sheplyakov Alexei
varg at theor.jinr.ru
Thu Apr 5 13:28:01 CEST 2007
Hello,
On Wed, Apr 04, 2007 at 09:34:24PM -0400, David Fang wrote:
> > C++ standard allows this (see e.g. 14.7.3).
> >
> > So, this is OK:
> >
> > template<typename T> class foo {
> > static T data;
> > };
> >
> > template<typename T> class foo<T*> {
> > static void* data;
> > };
> >
> > template<typename T> T foo<T>::data = T(1);
> >
> > template<typename T> void* foo<T*>::data = 0;
>
> Hi,
> This alone doesn't exhibit the issue in the original example.
> What you've written above is just a plain partial specialization, no
> violation at all.
IMHO the patch in question is just explicit specialization, no violations
either.
> Now, suppose that the last definition above
> (foo<T*>::data) was replaced in a *different* translation unit with:
>
> template <> void* foo<void*>::data = &something_else;
>
> which is similar to the original code in this thread. The instantiation
> of foo<void*>::data can now be different-valued. (Is this analogous to
> the GiNaC source or proposed patch in question?)
That's a different story. What we have is _equivalent_ explicit
specialization, like
template<typename T> class bar {
static void* data;
};
template<typename T> bar<T>::data = 0;
struct baz { };
// in a different translation unit:
template<> bar<baz>::data = 0;
So there should be no any difference. But... Apparently compiler generates
different code:
// With explicit specialization
$ nm -B -C build/ginac/ginac/.libs/libginac.so | grep -e '::first'
0032bc8c B GiNaC::class_info<GiNaC::print_context_options>::first
0032bc84 B GiNaC::class_info<GiNaC::registered_class_options>::first
// _Without_ explicit specialization
nm -B -C build/ginac/ginac/.libs/libginac.so | grep -e '::first'
002611d0 V GiNaC::class_info<GiNaC::print_context_options>::first
00261168 V GiNaC::class_info<GiNaC::registered_class_options>::first
I need to re-read the standard to understand what's going on...
Best regards,
Alexei
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20070405/872dd620/attachment.pgp
More information about the GiNaC-list
mailing list