This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

minor bug: pointers to static member functions that otherwise inline



    I've run into some problems with code that passes around pointers to
static member functions. What happens is, if the only way the function is
'used' is by taking a pointer to it, the compiler doesn't actually generate
the code for that function. This forces me to add -fkeep-inline-functions to
avoid a crash. Is this behavior correct?

    Here's example code off the top of my head (but it may be too simple to
produce the bug):

class foo
{
 public:
 int a;
 foo() { a=0; }
 static void inc(void *j)
 {
  foo *b=(foo *)j;
  b->a++;
 }
};

void runner(void (*foo)(void *), void *param)
{
 foo(param);
}

int main(void)
{
 foo g;
 runner(foo::inc, (void *)&g);
 return 0;
}

    When I compile this without -fkeep-inline-functions, foo::inc gets
optimized out even though an address that claims to be for that function
gets passed to runner. If I take the address of a function, shouldn't the
compiler consider that an instance it can't inline?

    (Please reply by email as well if possible. Thanks.)

----------------------------------------------------------------------
David Schwartz <davids@webmaster.com>
http://www.gate.net/~djls




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]