From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6D1DA3857C47 for ; Fri, 7 Jan 2022 00:22:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D1DA3857C47 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-389-7EokBysAOkq7uEMeA5kJxw-1; Thu, 06 Jan 2022 19:22:10 -0500 X-MC-Unique: 7EokBysAOkq7uEMeA5kJxw-1 Received: by mail-qv1-f69.google.com with SMTP id o14-20020ad45c8e000000b004112b52fc2cso3563357qvh.6 for ; Thu, 06 Jan 2022 16:22:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=roHbRcB3Q5yxMPpQ/PQm/xCek6hLuTmyGns78Ss8JHM=; b=wAoKwrOJHTR8OJabYeV9fzsR3z9GCqRe5v6/7ysgT8dDWbmI6nYNbIQ2NA/LIiKbrS bBGVhT9XdqW9XR+4eZAbXhP/LKaJ18SLKZUqNZfOARq/J4r5xyme9dkKYfJ8Mz89DTj3 IV0cZfaxUIFSJitFEF5hkCUD59UTcWURHCLHTtEi97+caV1EhTc4PRQC5a0LB0q98RUk CbaGaNkYlP4ATfyfDCRBiWwTsjW7kOMR4rQWeBiCdnnYctMM58tLqHh/iOtkcZat/E/G sotzQ5rm8PRw4uCfITA5Jd6TLgfwcoyh1kA4giQje82NZkPaaCXOsFEM/u2ecyVcEFrd fdVg== X-Gm-Message-State: AOAM532ecpNBBSL/fS+dS2BSuI3JlC3KBXf/mshILCBos7r6NK1NLcY3 oAtUqHapigo2z93bi1WccIHKmlBJ2hkjIaWtMcJhfKUWu1Fvo2Nl27ChK32AjgGNTF2InohPIeD W3gaFIkyLZlIyS0NlHWl2q3zF1ICiVDfKqOgGGCxV3zSK4qzkuq/KJGl8ECU6hnuI2A== X-Received: by 2002:ad4:596b:: with SMTP id eq11mr32966443qvb.16.1641514929607; Thu, 06 Jan 2022 16:22:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxL2SK37lydu7h/mR98biP++4BL1XpdejsRh7HEZCsq/UANGtUA9UuK0HJJEZSWDD5DX1YcZA== X-Received: by 2002:ad4:596b:: with SMTP id eq11mr32966425qvb.16.1641514929234; Thu, 06 Jan 2022 16:22:09 -0800 (PST) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s3sm2323785qkp.93.2022.01.06.16.22.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 16:22:08 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed 10/11] c++: nested catch in ctor fn-try-block [PR61611] Date: Thu, 6 Jan 2022 19:21:55 -0500 Message-Id: <20220107002156.2992278-10-jason@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220107002156.2992278-1-jason@redhat.com> References: <20220107002156.2992278-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2022 00:22:13 -0000 Being in_function_try_handler isn't enough to satisfy the condition of reaching the end of such a handler; in this case, we're reaching the end of a handler within that handler, so we don't want the special semantics. PR c++/61611 gcc/cp/ChangeLog: * except.c (in_nested_catch): New. (expand_end_catch_block): Check it. gcc/testsuite/ChangeLog: * g++.dg/eh/ctor-fntry1.C: New test. --- gcc/cp/except.c | 20 +++++++++++++++++++- gcc/testsuite/g++.dg/eh/ctor-fntry1.C | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/eh/ctor-fntry1.C diff --git a/gcc/cp/except.c b/gcc/cp/except.c index bcd9f84431b..9b746be231a 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -448,6 +448,23 @@ expand_start_catch_block (tree decl) return type; } +/* True if we are in a catch block within a catch block. Assumes that we are + in function scope. */ + +static bool +in_nested_catch (void) +{ + int catches = 0; + + /* Scan through the template parameter scopes. */ + for (cp_binding_level *b = current_binding_level; + b->kind != sk_function_parms; + b = b->level_chain) + if (b->kind == sk_catch + && ++catches == 2) + return true; + return false; +} /* Call this to end a catch block. Its responsible for emitting the code to handle jumping back to the correct place, and for emitting @@ -463,7 +480,8 @@ expand_end_catch_block (void) a handler of the function-try-block of a constructor or destructor. */ if (in_function_try_handler && (DECL_CONSTRUCTOR_P (current_function_decl) - || DECL_DESTRUCTOR_P (current_function_decl))) + || DECL_DESTRUCTOR_P (current_function_decl)) + && !in_nested_catch ()) { tree rethrow = build_throw (input_location, NULL_TREE); /* Disable all warnings for the generated rethrow statement. */ diff --git a/gcc/testsuite/g++.dg/eh/ctor-fntry1.C b/gcc/testsuite/g++.dg/eh/ctor-fntry1.C new file mode 100644 index 00000000000..0c783bb45ee --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/ctor-fntry1.C @@ -0,0 +1,23 @@ +// PR c++/61611 +// { dg-do run } + +struct A { }; +struct B { }; + +struct Test +{ + Test() + try { throw A(); } + catch(const A&) + { + try { throw B(); } + catch(const B&) { } + } +}; + +int +main() +{ + try { Test x; } + catch(const A&) { } +} -- 2.27.0