Updated mangling specs
Daveed Vandevoorde
daveed at edg.com
Thu Jan 27 19:39:07 UTC 2000
mendell at ca.ibm.com wrote:
>
> Our template/standard guy thinks that this is not essential. His words:
>
> My understanding of 14.5.5.1 is that it says that this mangling is not
> required. Paragraphs 6 to 8 define equivalent and functionally
> equivalent expressions and function templates.
>
> 'I + 10' and 'I + 1 + 2 + 3 + 4' are not equivalent but they are
> functionally equivalent.
>
> I think the mangling described below could be used to make all
> nonequivalent functions disctinct, but these paragraphs state that only
> functionally equivalent function template are distinct.
That only goes for the nondependent constant expressions (you're free to
evaluate them or not).
However, if the depend components of the expression differ, the template
signatures differ.
Consider the following example:
// file 1:
template<int I> int f(A<I+1>::X) { return 1; }
template void f<1>(A<2>::X);
// file 2:
template<int I> int f(A<2*I>::X) { return 2; }
template void f<1>(A<2>::X);
Two distinct functions are instantiated in this program and that is fine.
So we must be able to differentiate them.
This is in fact what paragraph 5 of 14.5.5.1 says:
When an expression that references a template parameter is used in
the function parameter list or the return type in the declaration of
a function template, the expression that references the template
parameter is part of the signature of the function template. This is
necessary to permit a declaration of a function template in one
translation unit to be linked with another declaration of the function
template in another translation unit and, conversely, to ensure that
function templates that are intended to be distinct are not linked
with one another. [Example:
template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1
template <int I, int J> A<I-J> f(A<I>, A<J>); // different from #1
--- end example] [Note: Most expressions that use template parameters
use non-type template parameters, but it is possible for an expression
to reference a type parameter. For example, a template type parameter
can be used in the sizeof operator. ]
Daveed
More information about the cxx-abi-dev
mailing list