[LLVMbugs] [Bug 10341] New: ::delete acts like regular delete for classes with virtual destructor

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 12 13:59:49 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10341

           Summary: ::delete acts like regular delete for classes with
                    virtual destructor
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ppelletier at oblong.net
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Created an attachment (id=6876)
 --> (http://llvm.org/bugs/attachment.cgi?id=6876)
delete-test.C

Although c++ is a complex language and I could easily be wrong about what the
correct behavior should be, I believe I have found a bug in clang.  In any
case, clang behaves differently for my testcase (which I have attached to this
bug) than gcc and Visual C++, and I got a reply to my query on the mailing list
which suggests this is indeed a clang bug:

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-July/016070.html

The bug is that I would expect "::delete" to call "::operator delete" after
running the class's destructor.  For classes without a virtual destructor, this
is indeed what happens.  However, for classes with a virtual destructor, after
clang calls the destructor, it calls the class's operator delete, rather than
the global one.  In other words, "::delete" seems to act like "delete" if the
class has a virtual destructor.  This is different than how gcc and Visual C++
behave; they both call the global operator delete when "::delete" is used,
regardless of whether the class has a virtual destructor or not.

ppelletier at pumpkin:~/misc$ uname -a
Linux pumpkin 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:09:38 UTC 2010
x86_64 GNU/Linux
ppelletier at pumpkin:~/misc$
/home/ppelletier/src/asan/asan_clang_Linux/bin/clang++ --version
clang version 3.0 (trunk 133511)
Target: x86_64-unknown-linux-gnu
Thread model: posix
ppelletier at pumpkin:~/misc$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ppelletier at pumpkin:~/misc$
/home/ppelletier/src/asan/asan_clang_Linux/bin/clang++ -O3 -Wall -o
delete-test-clang delete-test.C
ppelletier at pumpkin:~/misc$ g++ -O3 -Wall -o delete-test-gcc delete-test.C
ppelletier at pumpkin:~/misc$ ./delete-test-clang
destructor for 1
[1] I would expect this to be printed (and it is)
destructor for 2
[2] I would not expect this to be printed (gcc doesn't, clang does)
destructor for 3
ppelletier at pumpkin:~/misc$ ./delete-test-gcc
destructor for 1
[1] I would expect this to be printed (and it is)
destructor for 2
destructor for 3
ppelletier at pumpkin:~/misc$

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list