How do I control inline expansion of templates?
> >"inline" is only ever a hint to the compiler. You can disable or
> >of story I'm afraid.
I know that the compiler is allowed to not inline even though the
function is marked inline. My problem is the opposite: it inlines
although I tried to tell it not to. The question is still: how do you
disable inlining for a particular function in a class template without
disabling inlining globally?
> >The probable reason your template class's method gets inlined is
that it is
> >implemented in with the class definition which automatically hints
> >method as inline (standard ANSI C++).
No. I'm well aware of that and that's not the reason.
> VC++ tends to inline non-inline designated function templates that are
> defined outside of class definitions, especially when you compile with
> -O2. IIRC, VC2-4 were very aggressive about this, but using /O1
> instead of /O2 suppresses most of this unwanted inline expansion in
> VC5 and later.
It indeed behaves a lot more reasonable with /O1. Thanks for the tip.
However, as you have pointed out, the compiler still inline expands
occasionally (constructors seem to be its favorite candidates in my
code), although the code would be more compact if not inline expanded.
What it boils down to is that (at least) the documentation is wrong:
The description for the compiler option /Ob1 (Only __inline) states
that it "Expands only functions marked as inline or __inline or, in a
C++ member function, defined within a class declaration". When it comes
to templates, that's clearly not true.
Sent via Deja.com http://www.deja.com/
Before you buy.