From patchwork Thu May 9 20:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1933592 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=VPbMidFY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4Vb3PG1zGfz20fh for ; Fri, 10 May 2024 06:23:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 987763846426 for ; Thu, 9 May 2024 20:23:27 +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 01FB1385843B for ; Thu, 9 May 2024 20:23:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01FB1385843B 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 01FB1385843B 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=1715286187; cv=none; b=KplciPrDUciKbJTS8kdTAMpP5XAJJCwfAIUkINzl3a+3vE2jX1C6O5Zpte1Yp2MJcEHG5S1zajN225SKTr6WrrMfMZ+Z328N1N2Taa5VTxibUkY8m5WnIlQM3R86x4xRYdjV4LnzKLEU+d95fO2dL023tPC3Z70wwlT5cNF2SBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715286187; c=relaxed/simple; bh=NWkqTfm3egt2zz9iv4uVnV5kyx+H21oUvi2llF94jnQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FBpMVrPn+AUfJlUfeSs/Z6DdaVLt2+r0KG4J1UGCpLuL5BQ9Gv+MOazvwvmlEYuxlw79GUqJzkVY1hcZ9LYcHUWK4FjMIldDoLV7fgoa467ZUdvz5c29QssHjseTpOmUf0nfVcoYguJ9DaRQyZ8Sgtw4fXoZNcmvzMrGbMrR6ZM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715286185; 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=LMYWYPqbnphJR818S8hiQ2B/KO1Afcgk+4eTt6Qq2ug=; b=VPbMidFYYZgyelwl9vIP4BreBhQLyI28hZNf8cyxWGMl57TdonsSTiXdh3H51dPtlIgmo1 R61LDbL0cli6keLEbXtXg/IIr3pV0/t5rqXg41U5L9tKmOein6KhIebIY0FR5o9iErUYoB ph79+a0JQZRvQniZXmY6+4rSOzn4yoc= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-5_FPlIXBNzCoWHFER7e3XA-1; Thu, 09 May 2024 16:23:04 -0400 X-MC-Unique: 5_FPlIXBNzCoWHFER7e3XA-1 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6f02a2ef280so1667410a34.1 for ; Thu, 09 May 2024 13:23:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715286183; x=1715890983; 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=LMYWYPqbnphJR818S8hiQ2B/KO1Afcgk+4eTt6Qq2ug=; b=aGRecMg0cAbB+AHR/Qx5ZrE9IIv4+lsh8mVuPtnfvYAVc4xAtUGLdisubajc2drd2L sjrYF2dFFZVQjENbaog2TNr1SHvXZ0rLIvdnsApcQq99xoSsy9i9lH26JZdw5m06x0CW qeCrwV2hq3oPRAiqQMqd7EO85Elhwx+KmrOexApNRZp/0ODtqZmAIoPrHx669TMGOMhR 82mbK19j6VXYQ2sMg+8gdxmBxEM+30mQtk4gE+YuAIOf8Q6bYW9B0eKePxjiq5QFdRdJ S06esLSph2Ow1grJS1VOMqceGYUcVMaV8iC+8IWv52Rd2BIlobOTQs2X9+qhsnrazwMw T2vQ== X-Gm-Message-State: AOJu0YxVXRol/Ym371rx6j+osPWcEbpHGPdZer8DiY069wlosJLHXcJK nywnXGWd9bzZRKTj2GWW+mlU8dEgFNxmM4RJtsO/PIrMle0LzDVqmERA/MGwf6S1OxJ/3HH8fjA tEZB5fGXHZzOT6wK7M0k7KiG0GURWtMBX8ZcSLEqRYtfglZfC1jWWL67opa7Ssp94uwE1B6QMFm 4T0ewPZQdobzcsdcgA1wmtoIlkhEsPx4WNbgGK X-Received: by 2002:a05:6870:b28b:b0:229:6d0e:203b with SMTP id 586e51a60fabf-24172fb45a9mr847875fac.50.1715286183033; Thu, 09 May 2024 13:23:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSW3uGvCymF9KkoVpdjr4S3e1NA4eNwZ353dPmWT+/AUy6Qc2FqBF4Z9QU+WpNVA6e9JeMug== X-Received: by 2002:a05:6870:b28b:b0:229:6d0e:203b with SMTP id 586e51a60fabf-24172fb45a9mr847845fac.50.1715286182642; Thu, 09 May 2024 13:23:02 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf277377sm103172285a.2.2024.05.09.13.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 13:23:02 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: lvalueness of non-dependent assignment [PR114994] Date: Thu, 9 May 2024 16:23:00 -0400 Message-ID: <20240509202300.2742125-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.0.119.g0f3415f1f8 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 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, 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14? For trunk as a follow-up I can implement the mentionted representation change to use CALL_EXPR instead of MODOP_EXPR for a non-dependent simple assignment expression that resolved to an operator= overload. -- >8 -- r14-4111 made us check non-dependent assignment expressions ahead of time, as well as give them a type. Unlike for compound assignment expressions however, if a simple assignment resolves to an operator overload we still represent it as a (typed) MODOP_EXPR instead of a CALL_EXPR to the selected overload. This, I reckoned, was just a pessimization (since we'll have to repeat overload resolution at instantiatiation time) but should be harmless. (And it should be easily fixable by giving cp_build_modify_expr an 'overload' parameter). But it breaks the below testcase ultimately because MODOP_EXPR (of non-reference type) is always treated as an lvalue according to lvalue_kind, which is incorrect for the MODOP_EXPR representing x=42. We can fix this by representing such assignment expressions as CALL_EXPRs matching what that of compound assignments, but that turns out to require some tweaking of our -Wparentheses warning logic which seems unsuitable for backporting. So this patch instead more conservatively fixes this by refining lvalue_kind to consider the type of a (simple) MODOP_EXPR as we already do for COND_EXPR. PR c++/114994 gcc/cp/ChangeLog: * tree.cc (lvalue_kind) : Consider the type of a simple assignment expression. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent32.C: New test. --- gcc/cp/tree.cc | 7 +++++++ .../g++.dg/template/non-dependent32.C | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent32.C diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index f1a23ffe817..0b97b789aab 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -275,6 +275,13 @@ lvalue_kind (const_tree ref) /* We expect to see unlowered MODOP_EXPRs only during template processing. */ gcc_assert (processing_template_decl); + if (TREE_CODE (TREE_OPERAND (ref, 1)) == NOP_EXPR + && CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))) + /* As in the COND_EXPR case, but for non-dependent assignment + expressions created by build_x_modify_expr. */ + goto default_; + /* A non-dependent (simple or compound) assignment expression that + resolved to a built-in assignment function. */ return clk_ordinary; case MODIFY_EXPR: diff --git a/gcc/testsuite/g++.dg/template/non-dependent32.C b/gcc/testsuite/g++.dg/template/non-dependent32.C new file mode 100644 index 00000000000..54252c7dfaf --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent32.C @@ -0,0 +1,18 @@ +// PR c++/114994 +// { dg-do compile { target c++11 } } + +struct udl_arg { + udl_arg operator=(int); +}; + +void f(udl_arg&&); + +template +void g() { + udl_arg x; + f(x=42); // { dg-bogus "cannot bind" } +} + +int main() { + g(); +}