Re: C++ - inlining of functions returning an unwindable object

"Martin B." <>
Wed, 09 Dec 2009 12:55:17 +0100

          From comp.compilers

Related articles
C++ - inlining of functions returning an unwindable object (Martin B.) (2009-11-27)
Re: C++ - inlining of functions returning an unwindable object (=?ISO-8859-1?Q?Roland_Lei=DFa?=) (2009-12-07)
Re: C++ - inlining of functions returning an unwindable object (Martin B.) (2009-12-09)
| List of all articles for this month |

From: "Martin B." <>
Newsgroups: comp.compilers
Date: Wed, 09 Dec 2009 12:55:17 +0100
Organization: A noiseless patient Spider
References: 09-11-061 09-12-013
Keywords: C++, optimize
Posted-Date: 10 Dec 2009 02:22:25 EST

Roland Lei_a wrote:
> I tried your code with g++ 4.4.1 on amd64. g++ basically emits the
> same code for testsimple and testsimple2 and does not call the getter.
> I compiled with:
> g++ test.cpp -c -O3 -S

OK. So it's MSVC++ specific. An interesting other combination would
maybe be MinGW/32 ... may I'll get something running and compare that.

> Are you sure you turned on all optimizations? Perhaps declaring the
> getter as
> std::string get() const {
> return s_;
> }
> helps.

Oh, I specifically *haven't* enabled all optimizations. I only have
enabled inlining, which should be sufficient for this testcase. (Well,
it appears to be with MSVC++)

> Another important issue is the return value optimizatoin of C++.
> (though the
> article claims msvc++ supports this feature)

RVO is there with MSVC (it always is, no matter what optimization level).
This shouldn't have any bearing on inlining vs. not inlining I guess.

> Yet another thing one should not forget is that a language allowing
> pointers which may point to literally everywhere, pointer arithmetic
> and so on really makes headaches for compiler writers. C/C++
> enthusiasts often claim how fast pointers are but this is only the
> case if the compiler is _really_ smart. That's why Fortran is
> sometimes faster than C. And since std::string uses pointers
> internally this may be the reason why msvc++ is not able to inline the
> function.

Well. MSVC won't inline any function returning an unwindable object,
i.e. an object with a non-empty destructor, it doesn't have anything to
do with if the object has some pointer members.

The point I was making in my OP was that the generated assembly code
minus the call itself + semantics appear to be exactly the same with the
function inlined vs. not inlined, so it strange that MSVC++ will never
inline such functions.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.