C++ member methods defined inline in the class defintion

Hello,

I started playing with clang the other day and I realized it didn’t handle a fairly simple case.

#include <stdio.h>

class Test
{
public:
void TestingInlineMethod()
{
printf(“TestingInlineMethod!\n”);
}
};

int main(int argc, char* argv)
{
Test a;
a.TestingInlineMethod();

return 0;
}

Compiling this code resulted in a linking error.

brad-macbook:clang bradleymurray$ clang -ccc-clang-cxx test.cpp
Undefined symbols:
“__ZN4Test19TestingInlineMethodEv”, referenced from:
_main in cc-oKiqB0.o
ld: symbol(s) not found

Interested, I dug into the code a bit and tried to figure out what was going wrong. I’ve attached a patch that fixes the issue, but I’m not sure if it’s correct. Comments would be appreciated.

Thanks,
Brad Murray

inline_member_patch.txt (1.68 KB)

Hi Brad,

Coincidentally, I just fixed a very similar set of problems with c++ codegen. If you slap an inline keyword on that method, it should get codegen'd. The remaining bug is that Sema is not setting the "isinline" bit on the FunctionDecl for TestingInlineMethod. Are you interested in trying to figure out why? If you get the isinline bit set, codegen should do the right thing.

-Chris

Hello,

I started playing with clang the other day and I realized it didn't

handle

a
fairly simple case.

    #include <stdio.h>

    class Test
    {
    public:
        void TestingInlineMethod()
        {
            printf("TestingInlineMethod!\n");
        }
    };

    int main(int argc, char* argv[])
    {
        Test a;
        a.TestingInlineMethod();

        return 0;
    }

Compiling this code resulted in a linking error.

The state of C++ codegen is such that it's pretty futile to try anything
with it, Anders' efforts notwithstanding.

I'm just happy it actually gets to codegen.

Sebastian