From patchwork Mon Dec 18 19:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1877628 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=Zqzz51bp; 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 4Sv9RG409Bz1ydg for ; Tue, 19 Dec 2023 06:50:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92DDD3857BBF for ; Mon, 18 Dec 2023 19:50:32 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 7392B3857710 for ; Mon, 18 Dec 2023 19:50:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7392B3857710 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 7392B3857710 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702929020; cv=none; b=sUmGmREvfuW7FGMCWRiNQW1jlkeCYlROK/hP5CQZ+EZ4872V+raaXcy/3nLSGB4AydsjVt27fDHuqusjy9lNgdhYGc0Orcx+m1IU6cZUp+wRlm7jGGyXjN/PN154h42VxzW0iC//GmJOHP8sT732LFgEZI8HjVPh/eq4tGU1o+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702929020; c=relaxed/simple; bh=DYU7e4aQ7Sjjgjzo1+iD0aXM22nWy0dwkj6jyexslJQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TSZT+GLJPKdixm1wyaw0WV8XBHGRFOKhijUOlWEq6zZxG/qEtg5mJZ2LXVbBBFMPnzJEqKO/gRiiGv+Z4vQ89lU0Y6zoJO0QpHGffja8J5OSyilt2HieeT/HQoUfXV1Qf0uGWUY3rh1pU9GJ3gRt/KWO0QHPDz28ddSkOpZSQGw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702929019; 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: content-transfer-encoding:content-transfer-encoding; bh=i5ucLT/XsTQtnZRmPXX//UQUWIoxPUyhFNORDjF7B20=; b=Zqzz51bp3DwhFxQztjyiBfWXTQvA+i8V68u78VFkxDK5i4PU/6RQR7aWZo/35rGPJAwtjc hVsQa7x0eQLSkpJnkl2QDM2rJH42cBA8oJ18yl7UyJiJo64p6xiPW/zFJzIchkmGWMPM/0 zJ+qUtJTNUL8Zn6JN3GQprvsNbkpYNs= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-icDnnvzAOCegB_8c6zr7PA-1; Mon, 18 Dec 2023 14:50:17 -0500 X-MC-Unique: icDnnvzAOCegB_8c6zr7PA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-77f55466facso575083685a.1 for ; Mon, 18 Dec 2023 11:50:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702929016; x=1703533816; 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=i5ucLT/XsTQtnZRmPXX//UQUWIoxPUyhFNORDjF7B20=; b=fQcArHDj4r51ujBGzajV80lVkhnwvkGo3D3J96cZGf8iRfuRN0xmQ2e9DRuyD6oK+O Zlv3Gk2m9Ib3OQ6ZC0F4j1kIY9PifNBS9Laqs/feoTG1KIL2WaTcOG3cdcNAPCnfVeok dgvzXDAFUuUAz42LlRERTqT7zOJuEZPMgi3A7Tazfc+L2Ikh/FXz+PqCyK/3XpLTWRx0 iCju8YR3UuP11joe3G/4Eq2ExlnBDLoZZz3O/1TZ62Jvb04veUgTi5sYWkK/Qh0ZnPh1 vJIek0ILqaTKjKTzthQ1qfLT49MuRPxwmrnEXMKJWwCS3KErnPeQyYzCv5qLOXC0EKWm mkYQ== X-Gm-Message-State: AOJu0Yy1OPJQEdk1hwG+gkZOr9Y0Vft2SU1x3XKHEx00zteWELfwG97g Hynvedwr4yH7EPeamhhDzt/cy+/ev09lvFduXe4+GPE2r3r9sT2D31ghCXAlq58cz87WRMB4zH+ h0Z3/2gkC8dFMzy8zlOAtOMMdhDb4kmEcKZljtVImwwf85D/DycwGnYF/Q3W1JCl5+v8QjtLNpr A= X-Received: by 2002:a05:620a:8b03:b0:77f:363f:8934 with SMTP id qw3-20020a05620a8b0300b0077f363f8934mr22293807qkn.68.1702929015755; Mon, 18 Dec 2023 11:50:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJ+17CE7Xtgfpr1O5S9UkL849Oo0au8u+hjNo8hfWYikdJlM3bnUqWCY+IxatPAA63KGbjaA== X-Received: by 2002:a05:620a:8b03:b0:77f:363f:8934 with SMTP id qw3-20020a05620a8b0300b0077f363f8934mr22293795qkn.68.1702929015419; Mon, 18 Dec 2023 11:50:15 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id qq6-20020a05620a38c600b0077dc1476413sm8484109qkn.131.2023.12.18.11.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 11:50:15 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: local class memfn synth from uneval context [PR113063] Date: Mon, 18 Dec 2023 14:50:13 -0500 Message-ID: <20231218195013.1241371-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.76.g1a87c842ec 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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here we first use and therefore synthesize the local class operator<=> from an unevaluated context, which inadvertently affects synthesization by causing functions used within the definition (such as the copy constructor of std::strong_ordering) to not get marked as odr-used. This patch fixes this by using maybe_push_to_top_level in synthesize_method which ensures that cp_unevaluated_operand is cleared even in the function-local case. PR c++/113063 gcc/cp/ChangeLog: * method.cc (synthesize_method): Use maybe_push_to_top_level and maybe_pop_from_top_level. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-synth16.C: New test. --- gcc/cp/method.cc | 12 ++---------- gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C | 13 +++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 26e6eb79946..f645066077f 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1770,8 +1770,6 @@ decl_remember_implicit_trigger_p (tree decl) void synthesize_method (tree fndecl) { - bool nested = (current_function_decl != NULL_TREE); - tree context = decl_function_context (fndecl); bool need_body = true; tree stmt; location_t save_input_location = input_location; @@ -1795,10 +1793,7 @@ synthesize_method (tree fndecl) it now. */ push_deferring_access_checks (dk_no_deferred); - if (! context) - push_to_top_level (); - else if (nested) - push_function_context (); + bool push_to_top = maybe_push_to_top_level (fndecl); input_location = DECL_SOURCE_LOCATION (fndecl); @@ -1843,10 +1838,7 @@ synthesize_method (tree fndecl) input_location = save_input_location; - if (! context) - pop_from_top_level (); - else if (nested) - pop_function_context (); + maybe_pop_from_top_level (push_to_top); pop_deferring_access_checks (); diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C new file mode 100644 index 00000000000..8e59f7d2e46 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C @@ -0,0 +1,13 @@ +// PR c++/113063 +// { dg-do link { target c++20 } } + +#include + +int main() { + struct X { + auto operator<=>(const X&) const = default; + }; + X x; + static_assert(noexcept(x <=> x)); + static_cast(x <=> x); +}