[cfe-dev] cross compilation unit inline?

David Blaikie dblaikie at gmail.com
Thu Dec 1 16:52:34 PST 2011


On Thu, Dec 1, 2011 at 4:41 PM, Jonny Yu <yingshen.yu at gmail.com> wrote:
> I know this is not supported in traditional linker.
> But is this supported after enabling LTO?
> My experiment with Xcode 4.2 seems the answer is no, but I'd bring up to confirm.
> Specifically, I mean the sample code below,
>
> =TestClass.h=
> class A {
> public:
> void foo ();
> }
> =TestClass.cpp=
> inline void A::foo() {
>   // short code
> }
> =Main.cpp=
> #include "TestClass.h"
> void main() {
>    A a;
>    a.foo();
> }
>
> The situation is C++ FAQ recommend putting inline in cpp file is best practice to hide implementation details, and MSVC can build the above code by enabling LTCG. Porting this codebase to LLVM+clang seems I have to either expose inline functions or remove inline keyword. I still need build the same codebase on MSVC, so that's not ideal.

Seems like there's a little confusion here - the 'inline' keyword is
probably entirely ignored by MSVC there anyway. LTCG is probably just
making its own choice based on heuristics without the need for
developer guidance. LTO will do similarly, as far as I understand it.
Just drop the inline keyword & you should get reasonable behavior from
both compilers. If it changes MSVC's behavior I'll be surprised. If
Clang/LLVM's LTO doesn't make the right choices of inlining (within
reason - the heuristics used here can have subtle effects & it's not
necessarily going to be perfect in all cases)  you could probably file
a bug or at least ask a question here.

- David




More information about the cfe-dev mailing list