This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
minor bug: pointers to static member functions that otherwise inline
- To: <egcs at cygnus dot com>
- Subject: minor bug: pointers to static member functions that otherwise inline
- From: "David Schwartz" <davids at webmaster dot com>
- Date: Sun, 28 Dec 1997 22:20:13 -0500
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