From owner-freebsd-toolchain@FreeBSD.ORG Mon Jan 21 01:47:50 2013 Return-Path: Delivered-To: toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id EAD5BE5B; Mon, 21 Jan 2013 01:47:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 485FF98; Mon, 21 Jan 2013 01:47:50 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r0L1lj39069089; Mon, 21 Jan 2013 03:47:45 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r0L1lj39069089 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r0L1ljGk069088; Mon, 21 Jan 2013 03:47:45 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 21 Jan 2013 03:47:45 +0200 From: Konstantin Belousov To: Hongli Lai Subject: Re: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 Message-ID: <20130121014745.GD2522@kib.kiev.ua> References: <201301201652.r0KGq0d1042817@red.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="e3HNah56eoWqGn2Q" Content-Disposition: inline In-Reply-To: <201301201652.r0KGq0d1042817@red.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: toolchain@freebsd.org, pfg@freebsd.org X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jan 2013 01:47:51 -0000 --e3HNah56eoWqGn2Q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jan 20, 2013 at 04:52:00PM +0000, Hongli Lai wrote: >=20 > >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: =20 > >Keywords: =20 > >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 0= 9:23:10 UTC 2012 =20 > 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 sh= ould. 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. >=20 > I've attached a reproducible test case. You can also find it at http://fo= rums.freebsd.org/showthread.php?p=3D205804#post205804 and http://stackoverf= low.com/questions/14413703/why-does-catching-stdbad-cast-not-work-on-freebs= d-9. The code is compiled with the following GCC version: >=20 > $ 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] >=20 > 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 o= n FreeBSD 9.1 with Clang too. > >How-To-Repeat: > See attached C++ program. > >Fix: >=20 >=20 > Patch attached with submission follows: >=20 > #include > #include > #include >=20 > class foo { > public: > virtual ~foo() {} > }; >=20 > class bar: public foo { > public: > int val; > bar(): val(123) {} > }; >=20 > static void > cast_test(const foo &f) { > try { > const bar &b =3D dynamic_cast(f); > printf("%d\n", b.val); > } catch (const std::bad_cast &) { > printf("bad cast\n"); > } > } >=20 > int main() { > foo f; > cast_test(f); > return 0; > } >=20 Confirmed, and it seems that the culprit is libstdc++. At least replacing the system libstdc++.so.6 with the library from the stock build of gcc 4.7.2 (without touching libgcc_s.so.1) makes the catch operator working. --e3HNah56eoWqGn2Q Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJQ/J5AAAoJEJDCuSvBvK1BI5UP/2AEce74RrFLw7wirML0bt5w MaO0BP9Zb6ShKup60ON3oM3KJOjj0lL6mACQ7AU7mWic77Gh3Z0KOcUNqOhhdrfe bFcc/2eFAPE4nN82GCTJzjqhBeZdPzTqHKP7TTIqP9PWRhVzErS4Kk8BbY0ySF0E MsuEGVj75uIGkpopNYN4b9t+4iMVyR+BClnfwJCf/1jBeCCml3kD0gR5eVRV08Zw E8yO0zPKya1f0oXiT5Ks9SO8b1iXwtgksEagZdPeCobLfnG9Wo7vOP/fojnQTjJl dzWwz/vWmZlOo0YjpzEK3H1q+6WPXzGo4yXcx9uhLGZOufMmTJBzL/tdk2A3PCB/ UrEuJ7fRmn4gHfmpWMgQ5L8wClytMh7wvPUNL54Dws8mJifewISqKr9wFrR3ugUT YbzFGMhSgimOF1Xpvyqc9QXKd6tvPgs/YHojcannTPWk6rXtNu4zyTgwoxbRO6SM d4V5i+i2C4UvW/5YMZpmMFCY9v7cUUoqkkiREoY/53/6NDckENn7aTs04DebM4zw 2Jo2nmBOphVd54nE5i3OqhfjTyB2ssCkvNfviO6RmzQnMhHbWr9b0FjhDjfgHOam +lUlVvirHbBR3HAzBn5vPSYWi6XTJI0oCeiXopAwVQdyMUxXOCigkwNpqZ9TiZLR XmCeH4endI7u3vofi+KM =89Rf -----END PGP SIGNATURE----- --e3HNah56eoWqGn2Q--