Blog
GCC Is Unbelievable
Date: 7/2/2007
So I'm compiling and building Scribe and Lgi on Linux (SUSE 10.0, gcc 4.0.2 20050501) and it's crashing out with weird errors in the List class, which is one of the core container classes used by Lgi. After some hours I've isolated the issue, one of my destructors was not being called. Very weird, very very weird. So I single stepped through the code delete deletes the object and it jumps over to another source code file with a private class of the same name, and runs it's destructor instead of the local class.

So lets get this straight, in "GContainers.cpp" (part of liblgi.so)
class Item
{
public:
    Item() {}
    ~Item() { /* not called */ }
    void Delete()
    {
        delete this; // call goes to wrong destructor
    }
};
And over in the scribe binary there is a file ScribeLangDialog.cpp which implements the initial dialog where you choose the language:
class Item : public GListItem
{
public:
    Item() {}
    ~Item() { /* called from inside GContainers.cpp */ }
};
And neither class is public outside their own file.

Is this normal? Is it legal?

Btw MSVC++ v6 gets it right.
Comments:
lsoltero
11/02/2007 10:21am

I ran into this problem with GCC on either the mac or linux when porting xgate. I had to rename the class to circumvent the problem.

MSVC++ got it right for me.

I thought it was very weird. I just couldn't believe that i had to rename a class to get gcc to grok it.

--luis
Mathew Hounsell
15/02/2007 2:57am
Most likely a linking error; change the name of the class.
Try putting both in different local namespaces and add a using directive.

e.g
file0.cpp
namespace file0 {
claas A { ~A() { } }
}
using namespace file0;

file0.cpp
namespace file1 {
claas A { ~A() { } }
}
using namespace file1;
fret
15/02/2007 3:36am
What I found surprising is that it let me get as far as running the program. I would've thought the linker should pick this up.

I renamed the class.
 
Reply
From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]