Still more questions on GCC

Mark Mitchell mark at codesourcery.com
Mon Oct 29 21:35:20 UTC 2001


 Does GCC work in some different manner so that templates get compiled
> even if they are not referenced.  I don't know if I am even making sense
> here but I am worried that I may be trying to compile code in
> TecFramework that has never been compiled by our other compilers and thus
> may be buggy.  Is that possible?

Yes.  Many compilers, for example, will allow:

  template <class T>
  void f() {
    if
  }

as long as "f" is not compiled.  The standard requires a diagnostic for
this code, and GCC will issue the error.  There are many more complex
examples of a roughly similar nature; for example, many compilers will
not complain about:

  template <class T>
  void f() { int i = "abc"; }

but that is invalid according to the standard as well.

The exact rules are complex (they involve the notion of "dependent
types") but basically the code must be fairly reasonable, even if
it is not instantiated.

Of course, you may also be running into bugs in G++.

-- 
Mark Mitchell                mark at codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com



More information about the pooma-dev mailing list