public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58796] New: throw nullptr not caught by catch(type*)
@ 2013-10-18 20:03 seurer at us dot ibm.com
  2013-10-30 14:39 ` [Bug c++/58796] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: seurer at us dot ibm.com @ 2013-10-18 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58796
           Summary: throw nullptr not caught by catch(type*)
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: seurer at us dot ibm.com

C++ standard section 15.3
A handler is a match for an exception object of type E if
...
— the handler is of type cv T or const T& where T is a pointer or pointer to
member type and E is std::nullptr_t.

A catch handler of a pointer type (the "T" in the quote from the standard)
should catch a throw of nullptr (the E). This is different than, say, "throw 7"
which will only be caught by something like an int catch (7 being an int) and
not a long catch.

However, when you try this with gcc it doesn't work.  Only a catch with
nullptr_t will catch throws of nullptr; catches with other pointer types that
should catch it don't.  

Note that this may instead be an issue with the library.

This is the output I get from the program that follows:

About to 'throw nullptr' (first case)
Didn't catch 'throw nullptr' at all
About to 'throw nullptr' (second case)
Didn't catch 'throw nullptr' at all
About to 'throw nullptr' (last case)
Caught 'throw nullptr' as type 'std::nullptr_t'


#include <iostream>
#include <cstddef>

struct A {};
typedef int A::*PointerToMember;

int main() {
   try {
      try {
         std::cout << "About to 'throw nullptr' (first case)" << std::endl;
         throw nullptr;
      } catch (PointerToMember) { // This *should* catch throw nullptr...
         std::cout << "Caught 'throw nullptr' as type 'int
A::*PointerToMember'" << std::endl;
      }
   } catch (...) {
      std::cout << "Didn't catch 'throw nullptr' at all" << std::endl;
   }

   try {
      try {
         std::cout << "About to 'throw nullptr' (second case)" << std::endl;
         throw nullptr;
      } catch(void *) { // This *should* catch throw nullptr...
         std::cout << "Caught 'throw nullptr' as type 'void *'" << std::endl;
      }
   } catch (...) {
      std::cout << "Didn't catch 'throw nullptr' at all" << std::endl;
   }

   try {
      try {
         std::cout << "About to 'throw nullptr' (last case)" << std::endl;
         throw nullptr;
      } catch (PointerToMember) {
         std::cout << "Caught 'throw nullptr' as type 'int
A::*PointerToMember'" << std::endl;
      } catch(void *) {
         std::cout << "Caught 'throw nullptr' as type 'void *'" << std::endl;
      } catch(std::nullptr_t) {
         std::cout << "Caught 'throw nullptr' as type 'std::nullptr_t'" <<
std::endl;
      }
   } catch (...) {
      std::cout << "Didn't catch 'throw nullptr' at all" << std::endl;
   }

   return 0;
}
>From gcc-bugs-return-432162-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Oct 18 20:29:26 2013
Return-Path: <gcc-bugs-return-432162-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 20416 invoked by alias); 18 Oct 2013 20:29:25 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 20370 invoked by uid 48); 18 Oct 2013 20:29:22 -0000
From: "jsm28 at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/58797] New: Expand __builtin_copysignl inline for powerpc soft-float/e500v1
Date: Fri, 18 Oct 2013 20:29:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jsm28 at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cf_gcctarget
Message-ID: <bug-58797-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-10/txt/msg01306.txt.bz2
Content-length: 841

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX797

            Bug ID: 58797
           Summary: Expand __builtin_copysignl inline for powerpc
                    soft-float/e500v1
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jsm28 at gcc dot gnu.org
            Target: powerpc*-*-linux*

The powerpc port should have an insn pattern for copysigntf3 for soft-float and
e500v1; right now, the complex multiplication/division in libgcc ends up with
an undefined reference to copysignl in those configurations.  This doesn't
generally cause problems for glibc users - glibc has copysignl in libc as well
as libm - but can trip up users of other C libraries.


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
@ 2013-10-30 14:39 ` redi at gcc dot gnu.org
  2014-12-12 10:47 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2013-10-30 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-10-30
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I agree this looks like a bug. Reduced:

struct A {};
typedef int A::*PointerToMember;

int main() {
  try {
    throw nullptr;
  } catch (PointerToMember) { // This *should* catch throw nullptr...
  }

  try {
    throw nullptr;
  } catch(void *) { // This *should* catch throw nullptr...
  }
}


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
  2013-10-30 14:39 ` [Bug c++/58796] " redi at gcc dot gnu.org
@ 2014-12-12 10:47 ` paolo.carlini at oracle dot com
  2014-12-13  3:46 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-12-12 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jwakely.gcc at gmail dot com

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Looks like this is (also) a runtime issue: normally works on clang, but does
*not* if -stdlib=libstdc++ is added to the command line. Futher evidence: does
not work with icc, which uses the system runtime, but works with eccp.


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
  2013-10-30 14:39 ` [Bug c++/58796] " redi at gcc dot gnu.org
  2014-12-12 10:47 ` paolo.carlini at oracle dot com
@ 2014-12-13  3:46 ` redi at gcc dot gnu.org
  2014-12-15 13:59 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-13  3:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Target Milestone|---                         |5.0

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
--- a/libstdc++-v3/libsupc++/eh_personality.cc
+++ b/libstdc++-v3/libsupc++/eh_personality.cc
@@ -230,6 +230,13 @@ get_adjusted_ptr (const std::type_info *catch_type,
       *thrown_ptr_p = thrown_ptr;
       return true;
     }
+  if (throw_type == &typeid(nullptr))
+    {
+      if (catch_type->__is_pointer_p())
+       return true;
+      if (dynamic_cast<const __pointer_to_member_type_info*>(catch_type))
+       return true;
+    }

   return false;
 }

With that patch (which requires building eh_personality.cc with -std=gnu++11) I
get:


About to 'throw nullptr' (first case)
Caught 'throw nullptr' as type 'int A::*PointerToMember'
About to 'throw nullptr' (second case)
Caught 'throw nullptr' as type 'void *'
About to 'throw nullptr' (last case)
Caught 'throw nullptr' as type 'int A::*PointerToMember'


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
                   ` (2 preceding siblings ...)
  2014-12-13  3:46 ` redi at gcc dot gnu.org
@ 2014-12-15 13:59 ` redi at gcc dot gnu.org
  2015-04-22 12:01 ` jakub at gcc dot gnu.org
  2015-07-16  9:20 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-15 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
However with that patch the caught pointer is not null, so it's not right.


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
                   ` (3 preceding siblings ...)
  2014-12-15 13:59 ` redi at gcc dot gnu.org
@ 2015-04-22 12:01 ` jakub at gcc dot gnu.org
  2015-07-16  9:20 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-04-22 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|5.0                         |5.2

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 5.1 has been released.


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

* [Bug c++/58796] throw nullptr not caught by catch(type*)
  2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
                   ` (4 preceding siblings ...)
  2015-04-22 12:01 ` jakub at gcc dot gnu.org
@ 2015-07-16  9:20 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-07-16  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|5.2                         |5.3

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 5.2 is being released, adjusting target milestone to 5.3.


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

end of thread, other threads:[~2015-07-16  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 20:03 [Bug c++/58796] New: throw nullptr not caught by catch(type*) seurer at us dot ibm.com
2013-10-30 14:39 ` [Bug c++/58796] " redi at gcc dot gnu.org
2014-12-12 10:47 ` paolo.carlini at oracle dot com
2014-12-13  3:46 ` redi at gcc dot gnu.org
2014-12-15 13:59 ` redi at gcc dot gnu.org
2015-04-22 12:01 ` jakub at gcc dot gnu.org
2015-07-16  9:20 ` rguenth 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).