From patchwork Fri Mar 22 21:30:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1915075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a0jwzhuX; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V1b913x0Cz1yXr for ; Sat, 23 Mar 2024 08:30:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3EA00385843A for ; Fri, 22 Mar 2024 21:30:37 +0000 (GMT) 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 E96943858D32 for ; Fri, 22 Mar 2024 21:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E96943858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E96943858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711143019; cv=none; b=FA5gTrvigzwD8I/tLqeMYha+QWyJB7WN/H4gP0ykrLhPzCOXZywZBsEuUlPybvgOBpLYZaluliWqz59sK7PpvnYHtpMYRLtrvz4N0Mx5Kd7zAYqFCI5+SMWBNt9WxZHQoF3JBJRDVKdKAB1ZDgCVJWfkCZVOETaaNkSoOBLUl+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711143019; c=relaxed/simple; bh=ilAJ8wwWUjSFDWZukqnKjSiKuOJgrzz5Fv0gZhuAw+4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=aK+1/U5Nia8fTUCaoRBnLASfH9W9WlU0eEtRX1vF78FBPvGNuupNn+xEhAlipaH6758femm/f1CARy2pWMmk6HbDliODamc69QgVJyP54F28FWx4GU9S2T6V48mqIvyT6rX5uc7EZmgqYd5n9b5Pgx8GZDlEjKpiqPkhKKdgTcI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711143016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=igISXJRsxhXcR4O9U2tfzh9aqapfyCOwFc4NMOdP8Gk=; b=a0jwzhuXTXpi7Tlo1bFxflEEu32tgPyDMKcdcXqBBcBCtNxffqjFwsD59F8vKd0ba15MtU c0TdfYIRQLJ5hmkThbxX6iWHAXn2KLMWQz7hqAql45gJUEQNP93Ggp1gkJhDn2+0ER/TXs lezbqBxadSfkEhwrPDAXm//bdBj2FrA= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-2Iw4lqsBN6WL0GHubEPWJA-1; Fri, 22 Mar 2024 17:30:11 -0400 X-MC-Unique: 2Iw4lqsBN6WL0GHubEPWJA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-69673f50eacso6579116d6.2 for ; Fri, 22 Mar 2024 14:30:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711143011; x=1711747811; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=igISXJRsxhXcR4O9U2tfzh9aqapfyCOwFc4NMOdP8Gk=; b=IbKcHnb3jNhClDuWZ66t9CNeHlwQ5k/shze2pTHK3QtRiWlwMz5LuGArTUIw5Qot1p N1BvlX+N8DFKSn7yjHULVOvWoBG9ewAN/OYNCiog4Upi3SADQOazLPTKRFyJAy6uvqKV knlJWgdy9FqDlUSunxDC2kXwJEaub20BW6iaylDEOIF7hdHhXHlCIHGALB/FdW8Gxhgd TQm88uoOdvwLNnXMvjbTRg9a9YNKPJZceMb/eOugCXBRTMJVQet4NKURSFf9GJaRZs4T YfPO+b8Yc4WXj1hZl8LISJ0Cvv9cd5foMpXSSeKefig6ahkUpExO9fqj9WIzx3TORYzC FBBQ== X-Gm-Message-State: AOJu0YxCPyAjTVma4sWl8t75XsqrUCP2y1ExGgaUVTR6xuhVYzzO5vkq PDKNNsN39DXxRKOpUA46Vv27xjnB/+ZHu/eg8+lofdWHa1VuXD+YeEAqBAgQXHAg8oRae46DxvA NhbDsfeHXKrkbiHMFhCtlVOG3aKiWrG9TM7F4iX44UqrJAfK8CoqnaKg= X-Received: by 2002:a05:6214:1cc1:b0:691:8661:1069 with SMTP id g1-20020a0562141cc100b0069186611069mr568198qvd.25.1711143011151; Fri, 22 Mar 2024 14:30:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLTxIm3i9SdFLYF1yTas075EmgAXDx+tNIOL1CCxB7pRsuGMltW/fxBKrUOeB1A9ysfQha+w== X-Received: by 2002:a05:6214:1cc1:b0:691:8661:1069 with SMTP id g1-20020a0562141cc100b0069186611069mr568181qvd.25.1711143010777; Fri, 22 Mar 2024 14:30:10 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id jl7-20020ad45e87000000b0068f35e9e9a2sm1465060qvb.8.2024.03.22.14.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 14:30:10 -0700 (PDT) Date: Fri, 22 Mar 2024 17:30:08 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches , Patrick Palka Subject: [PATCH v2] c++: ICE with noexcept and local specialization, again [PR114349] Message-ID: References: <20240321210112.941228-1-polacek@redhat.com> <80bc1760-f600-4ebf-909d-0a238c6a4e0b@redhat.com> MIME-Version: 1.0 In-Reply-To: <80bc1760-f600-4ebf-909d-0a238c6a4e0b@redhat.com> User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-11.6 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org On Thu, Mar 21, 2024 at 05:27:37PM -0400, Jason Merrill wrote: > On 3/21/24 17:01, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > -- >8 -- > > Patrick noticed that my r14-9339-gdc6c3bfb59baab patch is wrong; > > we're dealing with a noexcept-spec there, not a noexcept-expr, so > > setting cp_noexcept_operand et al is incorrect. Back to the drawing > > board then. > > > > To fix noexcept84.C, we should probably avoid doing push_to_top_level > > in certain cases. Patrick suggested checking: > > > > const bool push_to_top = current_function_decl != fn; > > > > which works, but I'm not sure I follow the logic there. I also came > > up with > > > > const bool push_to_top = !decl_function_context (fn); > > > > which also works. But ultimately I went with !DECL_TEMPLATE_INSTANTIATED; > > if DECL_TEMPLATE_INSTANTIATED is set, we've already pushed to top level > > if it was necessary in instantiate_body. > > This sort of thing is what maybe_push_to_top_level is for, does that also > work? Sadly -- and I should have mentioned that -- no. maybe_push_to_top_level asks: bool push_to_top = !(current_function_decl && !LAMBDA_FUNCTION_P (d) && decl_function_context (d) == current_function_decl); here both d and current_function_decl are test()::S::S(), and decl_function_context (d) is test(). (current_function_decl was set to test()::S::S() by an earlier push_access_scope call.) But I want it to work, and I think using maybe_ would be a way nicer fix. So what if we don't push to top level if decl_function_context is non-null? I had to add the LAMBDA_TYPE_P check though: it looks that we always have to push to top level for lambdas, but sometimes we get a lambda's TYPE_DECL, and LAMBDA_FUNCTION_P doesn't catch that. An example is lambda-nested4.C. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Patrick noticed that my r14-9339-gdc6c3bfb59baab patch is wrong; we're dealing with a noexcept-spec there, not a noexcept-expr, so setting cp_noexcept_operand et al is incorrect. Back to the drawing board then. To fix noexcept84.C, we should probably avoid doing push_to_top_level in certain cases. maybe_push_to_top_level didn't work here as-is, so I changed it to not push to top level if decl_function_context is non-null, when we are not dealing with a lambda. This also fixes c++/114349, introduced by r14-9339. PR c++/114349 gcc/cp/ChangeLog: * name-lookup.cc (maybe_push_to_top_level): For a non-lambda, don't push to top level if decl_function_context is non-null. * pt.cc (maybe_instantiate_noexcept): Use maybe_push_to_top_level. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept85.C: New test. * g++.dg/cpp0x/noexcept86.C: New test. --- gcc/cp/name-lookup.cc | 12 ++++++--- gcc/cp/pt.cc | 11 ++------- gcc/testsuite/g++.dg/cpp0x/noexcept85.C | 33 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/noexcept86.C | 25 +++++++++++++++++++ 4 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept85.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept86.C base-commit: 65b7d1862e11784a0ce67ab758e06dd8aa65b181 diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index dce4caf8981..4b2b27bdd0d 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -8664,10 +8664,14 @@ maybe_push_to_top_level (tree d) { /* Push if D isn't function-local, or is a lambda function, for which name resolution is already done. */ - bool push_to_top - = !(current_function_decl - && !LAMBDA_FUNCTION_P (d) - && decl_function_context (d) == current_function_decl); + const bool push_to_top + = (LAMBDA_FUNCTION_P (d) + || (TREE_CODE (d) == TYPE_DECL + && TREE_TYPE (d) + && LAMBDA_TYPE_P (TREE_TYPE (d))) + || !current_function_decl + || (!decl_function_context (d) + && decl_function_context (d) != current_function_decl)); if (push_to_top) push_to_top_level (); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 8cf0d5b7a8d..7b00a8615d2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26855,7 +26855,7 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) } else if (push_tinst_level (fn)) { - push_to_top_level (); + const bool push_to_top = maybe_push_to_top_level (fn); push_access_scope (fn); push_deferring_access_checks (dk_no_deferred); input_location = DECL_SOURCE_LOCATION (fn); @@ -26878,17 +26878,10 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) if (orig_fn) ++processing_template_decl; - ++cp_unevaluated_operand; - ++c_inhibit_evaluation_warnings; - ++cp_noexcept_operand; /* Do deferred instantiation of the noexcept-specifier. */ noex = tsubst_expr (DEFERRED_NOEXCEPT_PATTERN (noex), DEFERRED_NOEXCEPT_ARGS (noex), tf_warning_or_error, fn); - --cp_unevaluated_operand; - --c_inhibit_evaluation_warnings; - --cp_noexcept_operand; - /* Build up the noexcept-specification. */ spec = build_noexcept_spec (noex, tf_warning_or_error); @@ -26898,7 +26891,7 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) pop_deferring_access_checks (); pop_access_scope (fn); pop_tinst_level (); - pop_from_top_level (); + maybe_pop_from_top_level (push_to_top); } else spec = noexcept_false_spec; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept85.C b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C new file mode 100644 index 00000000000..b415bb46bc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C @@ -0,0 +1,33 @@ +// PR c++/114349 +// { dg-do compile { target c++11 } } + +using A = struct {}; +template