public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65174] New: noexcept() returns true when operator delete with the object that has a throwing destructor
@ 2015-02-23 13:28 redboltz at gmail dot com
  2015-02-23 15:37 ` [Bug c++/65174] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: redboltz at gmail dot com @ 2015-02-23 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65174

            Bug ID: 65174
           Summary: noexcept() returns true when operator delete with the
                    object that has a throwing destructor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redboltz at gmail dot com

==========================================================================
Summary:
noexcept() returns true unexpectedly when the following conditions are
satisfied:
  1. noexcept argument expression is 'delete'.
  2. The argument of delete is the pointer literal that type has throwing
     destructor.
  3. The value of the pointer literal is null.
--------------------------------------------------------------------------
Test code: test.cpp
--------------------------------------------------------------------------
#include <iostream>

struct foo {
    ~foo() throw(std::bad_alloc) {}
};

int main() {
    std::cout << std::boolalpha;
    std::cout << noexcept(delete static_cast<foo*>(nullptr)) << std::endl;
    std::cout << noexcept(delete reinterpret_cast<foo*>(0)) << std::endl;
    std::cout << noexcept(delete reinterpret_cast<foo*>(1)) << std::endl;
}
--------------------------------------------------------------------------
Compile command:
g++ -Wall -Wextra -std=c++11 noexcept.cpp
--------------------------------------------------------------------------
Expected output:
false
false
false
--------------------------------------------------------------------------
Actual output:
true
true
false
--------------------------------------------------------------------------
gcc -v                                                                          
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-4.9-20150204/configure
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib
--disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.2 20150204 (prerelease) (GCC) 
==========================================================================


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

* [Bug c++/65174] noexcept() returns true when operator delete with the object that has a throwing destructor
  2015-02-23 13:28 [Bug c++/65174] New: noexcept() returns true when operator delete with the object that has a throwing destructor redboltz at gmail dot com
@ 2015-02-23 15:37 ` redi at gcc dot gnu.org
  2015-02-23 15:39 ` redi at gcc dot gnu.org
  2021-08-27 17:44 ` [Bug c++/65174] noexcept() returns true when operator delete with a NULL PTR " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-23 15:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65174

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Hmm, interesting. When the operand of the delete expression is null the
destructor is not invoked, so it can't throw. It's not obvious to me whether
GCC's result is allowed by the standard or not.


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

* [Bug c++/65174] noexcept() returns true when operator delete with the object that has a throwing destructor
  2015-02-23 13:28 [Bug c++/65174] New: noexcept() returns true when operator delete with the object that has a throwing destructor redboltz at gmail dot com
  2015-02-23 15:37 ` [Bug c++/65174] " redi at gcc dot gnu.org
@ 2015-02-23 15:39 ` redi at gcc dot gnu.org
  2021-08-27 17:44 ` [Bug c++/65174] noexcept() returns true when operator delete with a NULL PTR " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-23 15:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65174

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
FWIW clang and EDG both fail the first two static assertions here, while GCC
passes all three:

struct foo {
    ~foo() throw(int) {}
};

int main() {
    static_assert( noexcept(delete static_cast<foo*>(nullptr)), "");
    static_assert( noexcept(delete static_cast<foo*>(0)), "");
    static_assert( !noexcept(delete (1+static_cast<foo*>(0))), "");
}


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

* [Bug c++/65174] noexcept() returns true when operator delete with a NULL PTR that has a throwing destructor
  2015-02-23 13:28 [Bug c++/65174] New: noexcept() returns true when operator delete with the object that has a throwing destructor redboltz at gmail dot com
  2015-02-23 15:37 ` [Bug c++/65174] " redi at gcc dot gnu.org
  2015-02-23 15:39 ` redi at gcc dot gnu.org
@ 2021-08-27 17:44 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-27 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65174

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2018-10-17 00:00:00         |2021-8-27
            Summary|noexcept() returns true     |noexcept() returns true
                   |when operator delete with   |when operator delete with a
                   |the object that has a       |NULL PTR that has a
                   |throwing destructor         |throwing destructor
           Keywords|                            |wrong-code

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Updated testcase to show that noexcept will also cause it to happen so it does
matter for C++17+ (where throw(std::bad_alloc) support has been removed):
#include <iostream>

struct foo1 {
    ~foo1() noexcept(false) {}
};

int main() {
    std::cout << std::boolalpha;
    std::cout << noexcept(delete static_cast<foo1*>(nullptr)) << std::endl;
    std::cout << noexcept(delete reinterpret_cast<foo1*>(0)) << std::endl;
    std::cout << noexcept(delete reinterpret_cast<foo1*>(1)) << std::endl;
    return 0;
}

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

end of thread, other threads:[~2021-08-27 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 13:28 [Bug c++/65174] New: noexcept() returns true when operator delete with the object that has a throwing destructor redboltz at gmail dot com
2015-02-23 15:37 ` [Bug c++/65174] " redi at gcc dot gnu.org
2015-02-23 15:39 ` redi at gcc dot gnu.org
2021-08-27 17:44 ` [Bug c++/65174] noexcept() returns true when operator delete with a NULL PTR " pinskia at gcc dot gnu.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).