From patchwork Tue May 9 16:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1779047 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=v+5ZpZRH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QG3gV0Xg6z214S for ; Wed, 10 May 2023 02:35:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18B053857728 for ; Tue, 9 May 2023 16:35:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18B053857728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683650148; bh=Y3PtbyU0Y4i3js4TFokJCKqdvrLK+gIFqHDZns3f5gg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=v+5ZpZRHgaDVZcKpJoiEhoKjhSniL3jxFiBdIEfvmzlh/Om5f4YoKDEtR3IxLCTtf BHajokC/y+j4SVvtwVhTpJKRtLWmdPsKT1KDqjBxej10QbycFsHdSlMVG6bMKHkkkn Cgu4n8aq/kKoT+68RfK3u6BQvL4rJg451U03saiE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4DF2D3858C66 for ; Tue, 9 May 2023 16:35:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DF2D3858C66 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-0JjPSFbtNki1-swbYXijnQ-1; Tue, 09 May 2023 12:35:06 -0400 X-MC-Unique: 0JjPSFbtNki1-swbYXijnQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f389340bb7so19533571cf.3 for ; Tue, 09 May 2023 09:35:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683650105; x=1686242105; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y3PtbyU0Y4i3js4TFokJCKqdvrLK+gIFqHDZns3f5gg=; b=Vfr+A97B05e/qIFSNS+Gox0u07pAcC3wDSPiRkELycY86xvOFx/QtSdw7LdraMBb+R PFUZDvx0uS7b/VaqUbYHXO02Z13+7nDyhZDuqZa/HWQ0b0JsdRBHQPAC/A6QrVLfLXlV n/PZraufl+M7I3ICra8rH/3opBC7qfXg8nGRjVtytpIITU16LbjPpq9lVqYXM5IxZ8VT DM+ciZJJygw67nu6sBQz+ATGGFBoABCggzfLvr8quUKcJLdJBwe5rzxknX1d9kKoWkNc Fq2MW7R/FTkH5QY70f06OBS/w/zDxvEI010vHBwX1RAcQYgkUPufWInR381G1H0aspPq 54rw== X-Gm-Message-State: AC+VfDyZOTaPAIPGPBpPpnnpv4OhGmQuBrTgcQWaCWbJdlS8tIW68fA8 oFR2dlvM8g7x8YdM/6HOywPWkQohilN4kmUvuvKd74QHlefHFlkU+Gjs7X08/rqD8nJ+4oEglbQ S8UgPlEdhhC9EF+pBadt4lgH6q9ewd4sNpIoK43UhkQjKRLXZoV+nKkQKK8FjIPKh/qPcPCu9Vr A= X-Received: by 2002:ac8:5a83:0:b0:3f0:a511:174f with SMTP id c3-20020ac85a83000000b003f0a511174fmr21200045qtc.20.1683650105686; Tue, 09 May 2023 09:35:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Tibx6eOuxW6SCNuirRF/PXCvfVsbq2DuQH9/8ooaVivxR2YKnooomGM4wwlinvjADK4hf/g== X-Received: by 2002:ac8:5a83:0:b0:3f0:a511:174f with SMTP id c3-20020ac85a83000000b003f0a511174fmr21200015qtc.20.1683650105343; Tue, 09 May 2023 09:35:05 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 27-20020ac8561b000000b003ef3129a1a6sm623060qtr.46.2023.05.09.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 09:35:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: noexcept-spec from nested class confusion [PR109761] Date: Tue, 9 May 2023 12:35:02 -0400 Message-ID: <20230509163502.3746600-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.1.476.g69c786637d MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When processing a noexcept-spec from a nested class after completion of the outer class (since a noexcept-spec is a complete-class context), we pass to noexcept_override_late_checks the outer class type instead of the nested class type, which leads to bogus errors in the below test. This patch fixes this by making noexcept_override_late_checks obtain the class context directly via DECL_CONTEXT instead of via an additional parameter. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this looK OK for trunk and release branches? PR c++/109761 gcc/cp/ChangeLog: * parser.cc (cp_parser_class_specifier): Adjust call to noexcept_override_late_checks. (noexcept_override_late_checks): Remove 'type' parameter and use DECL_CONTEXT of 'fndecl' instead. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept78.C: New test. --- gcc/cp/parser.cc | 13 ++++++------- gcc/testsuite/g++.dg/cpp0x/noexcept78.C | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept78.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index d89553e7da8..7f4bc0f468e 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -251,7 +251,7 @@ static cp_token_cache *cp_token_cache_new static tree cp_parser_late_noexcept_specifier (cp_parser *, tree); static void noexcept_override_late_checks - (tree, tree); + (tree); static void cp_parser_initial_pragma (cp_token *); @@ -26458,7 +26458,7 @@ cp_parser_class_specifier (cp_parser* parser) /* The finish_struct call above performed various override checking, but it skipped unparsed noexcept-specifier operands. Now that we have resolved them, check again. */ - noexcept_override_late_checks (type, decl); + noexcept_override_late_checks (decl); /* Remove any member-function parameters from the symbol table. */ pop_injected_parms (); @@ -28240,14 +28240,13 @@ cp_parser_late_noexcept_specifier (cp_parser *parser, tree default_arg) } /* Perform late checking of overriding function with respect to their - noexcept-specifiers. TYPE is the class and FNDECL is the function - that potentially overrides some virtual function with the same - signature. */ + noexcept-specifiers. FNDECL is the member function that potentially + overrides some virtual function with the same signature. */ static void -noexcept_override_late_checks (tree type, tree fndecl) +noexcept_override_late_checks (tree fndecl) { - tree binfo = TYPE_BINFO (type); + tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl)); tree base_binfo; if (DECL_STATIC_FUNCTION_P (fndecl)) diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept78.C b/gcc/testsuite/g++.dg/cpp0x/noexcept78.C new file mode 100644 index 00000000000..e8156eb7c6f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept78.C @@ -0,0 +1,16 @@ +// PR c++/109761 +// { dg-do compile { target c++11 } } + +struct base { + virtual void foo() noexcept { } + virtual ~base() { } +}; + +struct outer : base { + struct nested { + void foo() noexcept(noexcept(g())); // { dg-bogus "looser" } + ~nested() noexcept(noexcept(g())); // { dg-bogus "looser" } + }; + static void g(); +}; +