[GiNaC-list] Problem using a user-defined class on Mac OS X.

David Fang fang at csl.cornell.edu
Thu Apr 5 03:34:24 CEST 2007

> > I may be jumping in a bit late, and without having looked through the
> > source, but are we looking at a violation of the basic one-definition-rule
> > (ODR)?
> No. There are no multiple definitions. Only one specialization (which
> provides best match) is selected by the compiler.
> > whereby a specialization is providing a definition that is
> > otherwise expected from a primary template?
> 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;

	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.  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?)

If I'm reading the following correctly (?): "Point of instantiation" [temp.point]:
A specialization for a function template, a member function template, or
of a member function or static data member of a class template may have
multiple points of instantiations within a translation unit. A
specialization for a class template has at most one point of instantiation
within a translation unit. A specialization for any template may have
points of instantiation in multiple translation units. If two different
points of instantiation give a template specialization different meanings
according to the one definition rule (3.2), the program is ill-formed, no
diagnostic required.

... says that points of instantiation that result in different meanings is
ill-formed.  The issue here is that one instantiation uses the primary
template definition, while another uses the [partial] specialization.
(Now if their separate definitions *happen* to be equivalent, I don't know
if that makes it well-formed again.)

> > (For the record, which version
> > are we looking at, so I may check it out?)


David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
	-- (2400 baud? Netscape 3.0?? lynx??? No problem!)

More information about the GiNaC-list mailing list