Proposal for mangling template partial specializations.
Coleen Phillimore
coleen at zko.dec.com
Mon Apr 17 18:18:04 UTC 2000
/*
I propose that partial specializations should be mangled differently than
template instantiations. The reasons:
1) It's the standard. 14.5.4 pp 3:
-3- Each class template partial specialization is a distinct template
and definitions shall be provided for the members of a
template partial specialization (temp.class.spec.mfunc).
Note that the end of paragraph 1 in this section says "no diagnostic is
required", but does that mean if a template instantiation can be linked
instead of a specialization and not violate the standard? Or does that
only mean that the compiler/linker is not required to diagnose the error
and can call the wrong version of the function?
2) Since this is a new ABI, users must recompile.
The correction to this problem is a source line change to declare
the specialization. We should strive to be 100% standard-compliant
with the new ABI, especially with a case we can diagnose. Users
should expect the new ABI to be 100% compliant as well.
The argument against making partial instantiations link incompatible with
is that users may depend on linking in the template instantiation when
the definition of partial instantiation is not available. Two points:
1) With the COMDAT model, if the partial instantiation is available in one
compilation unit and the template instantiation comes from another -
which will be picked? Isn't this really bad?
2) As a data point, DEC/Compaq changed the mangling for partial
specializations when using the new syntax (template <>) but kept the
mangling for them the same when using the old non-standard syntax (omit
the template <>). We don't have any entries about it in our database of
complaints. (We realize more code is written for Sun, HP, g++, etc,
so you may end up with complaints on code our compiler hasn't seen.)
So I propose a mangling qualifier for partial specializations on each template
argument that is specialized (maybe you don't need the 'E'):
<template-args> ::= I <template-arg>+ E
<template-arg> ::= <type> # type
<template-arg> ::= D <type> E # partially specialize'D'
<template-arg> ::= L <type> <value number> E # literal
<template-arg> ::= LZ <encoding> E # external name
<template-arg> ::= X <expression> E # expression
Coleen
*/
//
// Example of partial specialization [not] linking against template
// instantiation.
//
// spec.h
extern "C" int printf(const char *,...);
template <class T> class X { public:
void f(); // { printf("X<T>::f called\n"); }
};
// spec1.cxx
#include "spec.h"
main()
{
X<int> t;
t.f();
}
// spec2.cxx
#include "spec.h"
template <> class X<int> { public:
void f();
};
template <> void X<int>::f() { printf("X<int>::f();\n"); }
void foo()
{
X<int> x;
x.f();
}
//
// EDG/Compaq C++
% exx spec1.cxx spec2.cxx
spec1.cxx:
spec2.cxx:
ld:
Unresolved:
X<int>::f(void)
//
// Sun
33% CC spec1.cxx spec2.cxx
spec1.cxx:
spec2.cxx:
34% a.out
X<int>::f();
// G++
781% g++ spec1.cxx spec2.cxx
782% a.out
X<int>::f();
More information about the cxx-abi-dev
mailing list