public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42063]  New: g++ violate [class.dtor] when explicit destructor call
@ 2009-11-16  5:25 pi3orama at gmail dot com
  2009-11-16 13:17 ` [Bug c++/42063] " paolo dot carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-16  5:25 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]

This bug is related to the example in [class.dtor]/12 of standard N2960.

according to the example, in the following program:

#include <iostream>
struct B {
        virtual ~B() { std::cout << "~B" << std::endl; }
};

struct D : B {
        ~D ()  { std::cout << "~D" << std::endl; }
};

typedef B B_alias;
int main()
{
        D D_object;
        B* B_ptr = &D_object;
        std::cout << "begin" << std::endl;
        D_object.B::~B();
        B_ptr->~B();
        std::cout << "end" << std::endl;
        return 0;
}

D_object .B::~B () should call B¡¯s destructor, and
B_ptr ->~B () should call D's destructor.

However the actual result is

begin
~B
~B
end
...

the strange thing is when D_object.B::~B() be removed, or be swapped between
B_ptr->~B(), everything is OK.

Another problem: according to the spec, 'Once a destructor is invoked for an
object, the object no longer exists'. However, the following code shows that
g++ doesn't respect it:

#include <iostream>
struct C {
        ~C() { std::cout << "XXX" << std::endl; }
};
int main()
{
        C * c = new C();
        c->C::~C();
        delete c;
        return 0;
}

the program ends normally. Shouldn't it generate a double free fault?


-- 
           Summary: g++ violate [class.dtor] when explicit destructor call
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pi3orama at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42063


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-17 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-16  5:25 [Bug c++/42063] New: g++ violate [class.dtor] when explicit destructor call pi3orama at gmail dot com
2009-11-16 13:17 ` [Bug c++/42063] " paolo dot carlini at oracle dot com
2009-11-16 13:59 ` paolo dot carlini at oracle dot com
2009-11-17 10:02 ` redi at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).