Missing inlines?

Jonathan Wakely cow@compsoc.man.ac.uk
Thu Dec 11 09:28:00 GMT 2003


On Thu, Dec 11, 2003 at 10:00:49AM +0100, Joerg.Richter@pdv-FS.de wrote:

> >>I just looked at some STL header (GCC 3.2.1) and found that there are
> >>sometimes some 'inline' missing.
> >>
> >>For example in my installation the file
> >>include/bits/stl_tree.h
> >
> >There has been work on this file in mainline sources, so your sources
> >are out-of-date. You should be looking at 3.4/mainline sources.
> 
> I was aware of this fakt. 
> Btw. I found > 200 missing inlines in GCC 3.2.1 libstdc++-v3.
> 
> There where a lot in include/bits/stl_algo.h missing.

That's because they're templates and are probably too big to be inlined.

> I just looked at gcc-3.4-20031210 and I still see some. Eg. Line
> stl_algo.h:333
> 
>   template<typename _ForwardIterator>
>     _ForwardIterator
>     adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
>     {
> 
> But Bo Persson wrote that templates are automatic inline. So it should not
> matter. But it is interesting why it seems to fix my problems.

No, they're not automatically inline. A template definition could be
several thousand lines long in principle, and this would not be a good
candidate for inlining. Template definitions are allowed to appear in
more than one translation unit as long as the definitions are the same
(see [basic.def.odr] and [temp] in the standard).

This is similar to how an enum or class definition can be included in
several files, as long as the definitions are the same. Functions
declared "inline" are also allowed to appear in several translation
units, as long as the definition is the same - but this doesn't mean
that template/enum/class definitions need to be declared "inline".

jon

-- 
"In times like these, it helps to recall that there have always been
 times like these."
	- Paul Harvey



More information about the Libstdc++ mailing list