From patchwork Mon Apr 27 19:44:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 465205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1102F140083 for ; Tue, 28 Apr 2015 05:45:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Dma7dJbG; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=Ll9TPBOPkEq1Ut/Ma Ljtx2wqn3gdOz+zzlZvmumGPxBYz/ae+5h7pO9Mr2xvnMVm3+dYGEf1C/XJLNmLT x5veGcRA4Pvo7Du4wEDyNlh2plaG6kagzsQbdU9BhtGHR0GJ0hG6+eDe1cCiRZ5v DcmzuevHrxhm918mMr7ynBOa9o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=v7+wXOmzFnDIlObaXgrAOAh Y7Lg=; b=Dma7dJbGSUm6d2vBHfbVby3GsfHUy+Yv8hUImIOhkf/M0aquRIhhRKZ UWJ7OAJffgZTOOQG21swJgXjtj8bPBHQLaVy+K5O+nlb11vs1Ed5BcyQbDM06T+0 fEZJLfEfR4JsyTpmMny+0OIcD0ZOOwSYhJcmi+DcKNIKizi0/U+4= Received: (qmail 98901 invoked by alias); 27 Apr 2015 19:45:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98829 invoked by uid 89); 27 Apr 2015 19:45:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 27 Apr 2015 19:45:02 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3RJj00K028457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Apr 2015 15:45:01 -0400 Received: from localhost (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3RJj0j0026845; Mon, 27 Apr 2015 15:45:00 -0400 Date: Mon, 27 Apr 2015 20:44:59 +0100 From: Jonathan Wakely To: Michael Hanselmann Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH libstdc++] Fix for std::uncaught_exception (PR 62258) Message-ID: <20150427194459.GP3618@redhat.com> References: <5f7f8711e5f9f1cdbbd63a00f6d11a3766eb2765.1422844158.git.public@hansmi.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5f7f8711e5f9f1cdbbd63a00f6d11a3766eb2765.1422844158.git.public@hansmi.ch> User-Agent: Mutt/1.5.23 (2014-03-12) On 02/02/15 03:37 +0100, Michael Hanselmann wrote: >Calls to `std::uncaught_exception` after calling >`std::rethrow_exception' always return `true' when >`std::uncaught_exception' should return `false' unless an exception is >in flight. `std::rethrow_exception' does not update >`__cxa_eh_globals::uncaughtExceptions' while the following call to >`__cxa_begin_catch' decrements it. This fixes PR 62258. > >The original two-line patch was created by Dmitry Prokoptsev. Michael >Hanselmann implemented a testcase. Committed to trunk - thanks for the patch and test. commit 1cfba1875f21f485fe82e8c118b2355c4714bcdc Author: Jonathan Wakely Date: Mon Apr 27 13:48:23 2015 +0100 2015-04-27 Dmitry Prokoptsev Michael Hanselmann PR libstdc++/62258 * libsupc++/eh_ptr.cc (rethrow_exception): Increment count of uncaught exceptions. * testsuite/18_support/exception_ptr/62258.cc: New. diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc b/libstdc++-v3/libsupc++/eh_ptr.cc index 685c9e0..dae9246 100644 --- a/libstdc++-v3/libsupc++/eh_ptr.cc +++ b/libstdc++-v3/libsupc++/eh_ptr.cc @@ -245,6 +245,9 @@ std::rethrow_exception(std::exception_ptr ep) __GXX_INIT_DEPENDENT_EXCEPTION_CLASS(dep->unwindHeader.exception_class); dep->unwindHeader.exception_cleanup = __gxx_dependent_exception_cleanup; + __cxa_eh_globals *globals = __cxa_get_globals (); + globals->uncaughtExceptions += 1; + #ifdef _GLIBCXX_SJLJ_EXCEPTIONS _Unwind_SjLj_RaiseException (&dep->unwindHeader); #else diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc new file mode 100644 index 0000000..3734f19 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++11" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// PR libstdc++/62258 + +#include +#include + +struct check_on_destruct +{ + ~check_on_destruct(); +}; + +check_on_destruct::~check_on_destruct() +{ + VERIFY(std::uncaught_exception()); +} + +int main () +{ + VERIFY(!std::uncaught_exception()); + + try + { + check_on_destruct check; + + try + { + throw 1; + } + catch (...) + { + VERIFY(!std::uncaught_exception()); + + std::rethrow_exception(std::current_exception()); + } + } + catch (...) + { + VERIFY(!std::uncaught_exception()); + } + + VERIFY(!std::uncaught_exception()); +}