Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-12-08 08:33:57


Bear wrote:
> Hello there
>
> I'm getting a SIGSEGV when using the boost::shared_ptr in my program and
> compiling with the g++ -O2 option, whereas if I'm using the g++ -O0 option
> my programs works the way it should. My program is multi-threaded but to the
> best of my knowledge it is mutex'ed correctly.
>
> I compile my program the following way when using -O2 and -O0
>
> g++ -O0 -ggdb3 -DNDEBUG -DTTSERVER ....
> g++ -O2 -ggdb3 -DNDEBUG -DTTSERVER ....
>
> When I use gdb to step through the program (only with 'n') I go into the
> shared_count.hpp file when using the -O2 option whereas the version compiled
> with -O0 disregards this file in gdb.

Are you sure you don't have that the wrong way round?

> The -O2 version of the program crashes in the file checked_delete.hpp and
> the member "checked_delete":

You cannot find bugs in optimised programs using a source-level
debugger. The source locations you see are no more than a hint as to
the source of the machine code being run. An optimising compiler can
reorganise your code in ways you hadn't dreamed of.

Besides which, just because a bug shows up when deleting an object,
doesn't mean the bug is in the deletion.

To debug the problem, you will probably find it more useful to add debug
output to your program.

<snip>
> As I mentioned earlier, the -O0 run without problems. Has anyone experienced
> similar problems?
<snip>

Yes, I think most C and C++ programmers manage to produce bugs with this
sort of effect from time to time. That's nothing to do with Boost, though.

Ben.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net