Mangling of named constants
Mark Mitchell
mark at codesourcery.com
Thu Oct 17 01:16:28 UTC 2002
I've been asked to get clarification here about the following issue.
Given:
extern const int N = 3;
template <int I> struct S{};
template <int I> void f(S<N>) {}
template void f<7>(S<N>);
how is instantiation to be mangled? With "N" or with "3" as the
template argument to "S"?
The ISO C++ standard doesn't make us choose, as far as I can tell, in
that it deliberately leaves unspecified whether these two templates
are the same:
template <int I> void f(S<3>);
template <int I> void f(S<N>);
(If N has internal linkage, does that change anything?)
The ABI specification generally tries to mangle the source token
stream, which would suggest using "N".
The ABI does explicitly say that:
The encoding for a literal of an enumerated type is the encoding of
the type name followed by the encoding of the numeric value of the
literal in its base integral type (which deals with values that
don't have names declared in the type).
which is similar, but a little different in that there are enum
constants which have no name.
G++ uses the name "N", so it gets:
_Z1fILi7EEv1SILZ1NEE
I guess there are a couple of action items:
(1) Does the spec already say what we should do here?
If so, how can we make it clearer?
(2) If the spec does not mandate any particular behavior at this
point, what behavior should it mandate?
--
Mark Mitchell mark at codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
More information about the cxx-abi-dev
mailing list