Commit 469b759e by Jason Merrill

Formerly extend.texi.~114~

From-SVN: r13976
parent 9e148ceb
...@@ -3183,38 +3183,50 @@ problem, which I will refer to as the Borland model and the Cfront model. ...@@ -3183,38 +3183,50 @@ problem, which I will refer to as the Borland model and the Cfront model.
@table @asis @table @asis
@item Borland model @item Borland model
Borland C++ solved the template instantiation problem by adding the code Borland C++ solved the template instantiation problem by adding the code
equivalent of common blocks to their linker; template instances equivalent of common blocks to their linker; the compiler emits template
are emitted in each translation unit that uses them, and they are instances in each translation unit that uses them, and the linker
collapsed together at run time. The advantage of this model is that the collapses them together. The advantage of this model is that the linker
linker only has to consider the object files themselves; there is no only has to consider the object files themselves; there is no external
external complexity to worry about. This disadvantage is that complexity to worry about. This disadvantage is that compilation time
compilation time is increased because the template code is being is increased because the template code is being compiled repeatedly.
compiled repeatedly. Code written for this model tends to include Code written for this model tends to include definitions of all
definitions of all member templates in the header file, since they must templates in the header file, since they must be seen to be
be seen to be compiled. instantiated.
@item Cfront model @item Cfront model
The AT&T C++ translator, Cfront, solved the template instantiation The AT&T C++ translator, Cfront, solved the template instantiation
problem by creating the notion of a template repository, an problem by creating the notion of a template repository, an
automatically maintained place where template instances are stored. As automatically maintained place where template instances are stored. A
individual object files are built, notes are placed in the repository to more modern version of the repository works as follows: As individual
record where templates and potential type arguments were seen so that object files are built, the compiler places any template definitions and
the subsequent instantiation step knows where to find them. At link instantiations encountered in the repository. At link time, the link
time, any needed instances are generated and linked in. The advantages wrapper adds in the objects in the repository and compiles any needed
of this model are more optimal compilation speed and the ability to use instances that were not previously emitted. The advantages of this
the system linker; to implement the Borland model a compiler vendor also model are more optimal compilation speed and the ability to use the
system linker; to implement the Borland model a compiler vendor also
needs to replace the linker. The disadvantages are vastly increased needs to replace the linker. The disadvantages are vastly increased
complexity, and thus potential for error; theoretically, this should be complexity, and thus potential for error; for some code this can be
just as transparent, but in practice it has been very difficult to build just as transparent, but in practice it can been very difficult to build
multiple programs in one directory and one program in multiple multiple programs in one directory and one program in multiple
directories using Cfront. Code written for this model tends to separate directories. Code written for this model tends to separate definitions
definitions of non-inline member templates into a separate file, which of non-inline member templates into a separate file, which should be
is magically found by the link preprocessor when a template needs to be compiled separately.
instantiated.
@end table @end table
Currently, g++ implements neither automatic model. In the mean time, When used with GNU ld version 2.8 or later on an ELF system such as
you have three options for dealing with template instantiations: GNU/Linux or Solaris 2, g++ supports the Borland model. On other systems,
g++ implements neither automatic model.
A future version of g++ will support a hybrid model whereby the compiler
will emit any instantiations for which the template definition is
included in the compile, and store template definitions and
instantiation context information into the object file for the rest.
The link wrapper will extract that information as necessary and invoke
the compiler to produce the remaining instantiations. The linker will
then combine duplicate instantiations.
In the mean time, you have the following options for dealing with
template instantiations:
@enumerate @enumerate
@item @item
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment