Lifetime of local variables: global versus member function
Ian Lance Taylor
iant@google.com
Tue Mar 29 05:40:00 GMT 2011
Jan van Dijk <jan@epgmod.phys.tue.nl> writes:
> If I comment in line 11 of the library module (marked CULPRIT), thus calling
> class_scope_f(), and try again, the result is:
>
> Opening: /home/jan/src/gum-cvs/ideas/jan/libtest.so
> Handle after dlopen: 0x602050
> Handle after dlclose: 0x602050
> Exiting...
> Destructor called
>
> Now the library unloading fails (the handle is still !=0, and indeed the
> destructor of c is not called before the program terminates).
This certainly looks like a bug. I can recreate it using gcc 4.5.1 and
glibc 2.13.
> I assume this is because there is a difference in lifetime between local
> static variables in functions in global scope vs. those of member functions.
> Is this the intended behaviour? (I say 'intended', not 'mandated', because I
> know so's are beyond the scope of ISO-C++.) If not, should I file a report?
Please do file a bug report. Thanks.
Ian
More information about the Gcc-help
mailing list