The C++ template(1) facility, which effectively allows use of variables for types in declarations, is one of the newest features of the language.
GNU C++ is one of the first compilers to implement many of the template facilities currently defined by the ANSI committee.
Nevertheless, the template implementation is not yet complete. This chapter maps the current limitations of the GNU C++ template implementation.
These limitations apply to any use of templates (function templates or class templates) with GNU C++:
Function templates are implemented for the most part. The compiler can correctly determine template parameter values, and will delay instantiation of a function that uses templates until the requisite type information is available.
The following limitations remain:
template <class X> X min (X& x1, X& x2) { ... } int min (int, int); ... int i; short s; min (i, s); // should call min(int,int) // derived from template ...
f
:
template <class T> class A { public: T x; class Y {}; }; template <class X> int f (A<X>::Y y) { ... }
inline
function using templates, the compiler
can only inline the code after the first time you use
that function with whatever particular type signature the template
was instantiated.
Removing this limitation is akin to supporting nested function
definitions in GNU C++; the limitation will probably remain until the
more general problem of nested functions is solved.
enum
type alph
:
template <class T> class list { ... enum alph {a,b,c}; alph bar(); ... }; template <class T> list<int>::alph list<int>::bar() // Syntax error here { ... }
template <class T> class list { ... #ifdef SYSWRONG T x; #endif ... }The preprocessor output leaves sourcefile line number information (lines like `# 6 "foo.cc"' when it expands the
#ifdef
block. These
lines confuse the compiler while parsing templates, giving a syntax
error.
If you cannot avoid preprocessor conditionals in templates, you can
suppress the line number information using the `-P' preprocessor
option (but this will make debugging more difficult), by compiling the
affected modules like this:
g++ -P foo.cc -o foo
Debugging information for templates works for some object code formats, but not others. It works for stabs(2) (used primarily in A.OUT object code, but also in the Solaris 2 version of ELF), and the MIPS version of COFF debugging format.
DWARF support is currently minimal, and requires further development.
Go to the first, previous, next, last section, table of contents.