From owner-freebsd-standards@FreeBSD.ORG Sun Jan 20 17:00:01 2013 Return-Path: Delivered-To: freebsd-standards@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 322B4479 for ; Sun, 20 Jan 2013 17:00:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 16377B5C for ; Sun, 20 Jan 2013 17:00:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r0KH00OM031447 for ; Sun, 20 Jan 2013 17:00:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r0KH004A031442; Sun, 20 Jan 2013 17:00:00 GMT (envelope-from gnats) Resent-Date: Sun, 20 Jan 2013 17:00:00 GMT Resent-Message-Id: <201301201700.r0KH004A031442@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Hongli Lai Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 104B4282 for ; Sun, 20 Jan 2013 16:52:01 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id DBBFEB21 for ; Sun, 20 Jan 2013 16:52:00 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r0KGq0kL042818 for ; Sun, 20 Jan 2013 16:52:00 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id r0KGq0d1042817; Sun, 20 Jan 2013 16:52:00 GMT (envelope-from nobody) Message-Id: <201301201652.r0KGq0d1042817@red.freebsd.org> Date: Sun, 20 Jan 2013 16:52:00 GMT From: Hongli Lai To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jan 2013 17:00:01 -0000 >Number: 175453 >Category: standards >Synopsis: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jan 20 17:00:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Hongli Lai >Release: 9.1-RELEASE >Organization: Phusion >Environment: FreeBSD freebsd9 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: C++ code is not able to catch std::bad_cast exceptions, even though it should. If a dynamic_cast is within a try-catch block, then that block fails to catch std::bad_cast, and the program crashes with an uncaught exception as a result. I've attached a reproducible test case. You can also find it at http://forums.freebsd.org/showthread.php?p=205804#post205804 and http://stackoverflow.com/questions/14413703/why-does-catching-stdbad-cast-not-work-on-freebsd-9. The code is compiled with the following GCC version: $ gcc -v Using built-in specs. Target: amd64-undermydesk-freebsd Configured with: FreeBSD/amd64 system compiler Thread model: posix gcc version 4.2.1 20070831 patched [FreeBSD] FreeBSD 9.1 seems to be the only platform on which this bug appears. The code works as expected on Linux and OS X. According to a commenter, FreeBSD 9.0 works as expected too. According to another commenter the code fails on FreeBSD 9.1 with Clang too. >How-To-Repeat: See attached C++ program. >Fix: Patch attached with submission follows: #include #include #include class foo { public: virtual ~foo() {} }; class bar: public foo { public: int val; bar(): val(123) {} }; static void cast_test(const foo &f) { try { const bar &b = dynamic_cast(f); printf("%d\n", b.val); } catch (const std::bad_cast &) { printf("bad cast\n"); } } int main() { foo f; cast_test(f); return 0; } >Release-Note: >Audit-Trail: >Unformatted: