Re: Compiler-generated list of template instantiations?
Zara wrote:
On 26 Oct 2006 06:28:22 -0400, "Gene Bushuyev" <spam@spamguard.com>
wrote:
"Scott Meyers" <usenet@aristeia.com> wrote in message
news:12jvcl8lv5t855a@corp.supernews.com...
Nothing says fun in the sun like curling up with a copy of
the JSF C++ coding guidelines
(http://www.research.att.com/~bs/JSF-AV-rules.pdf), but I
was surprised to see this within:
The compiler should be configured to generate the list of actual
template instantiations.
In context, this sentence makes sense, but I've never heard
of a way to make a compiler generate a list of all template
instantiations (including the instantiation arguments).
Googling didn't yield anything obvious. Do people know of
ways for particular compilers to cause them to generate a
list of template instantiations? (I'm excluding things
like running nm or dumpbin on object files and the
demangling the names, as that doesn't qualify as generating
a list of instantiations.)
In Visual C++ you can request linker to create a map file
(/MAP:"mapfilename"), which among other things contains
template instantiations. The names in the map file are
mangled, and I don't know if filtering is available, never
happen to use it.
Pretty similiar with GCC, if you generate map listing, all non-inlined
template instantiations might be seen (mangled) on the gnu.linkonce.*
sections
On Unix based systems, you can do it easily after the fact,
using something like:
nm -C -p some_binary |
sed -e 's:operator<<:operator##:' -e 's:operator<:operator#:' |
egrep '<' |
sed -e 's:#:<:g' |
cut -c 12- |
sort -u
A quick check on one of my own binaries, however, makes me
wonder just how useful it is: there are an awful lot of entries
for things like
"void std::vector<Program::OpCode, std::allocator<Program::OpCode>
::_M_initialize_aux<__gnu_cxx::__normal_iterator<Program::OpCode*,
std::vector<Program::OpCode, std::allocator<Program::OpCode> > >
(__gnu_cxx::__normal_iterator<Program::OpCode*,
std::vector<Program::OpCode, std::allocator<Program::OpCode> > >,
__gnu_cxx::__normal_iterator<Program::OpCode*, std::vector<Program::OpCode,
std::allocator<Program::OpCode> > >, __false_type)",
which of course doesn't correspond to anything I wrote, or that
my collegues should code review.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]