From patchwork Tue Jun 25 01:00:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1951847 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=hZaTRIkG; 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 4W7RNH5RWDz20Z9 for ; Tue, 25 Jun 2024 11:01:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF2793846425 for ; Tue, 25 Jun 2024 01:00:52 +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 26C67384AB52 for ; Tue, 25 Jun 2024 01:00:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26C67384AB52 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 26C67384AB52 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=1719277231; cv=none; b=oKOOMhAe5hZqySq0OOgK5jy0irX7sMzoV+n4xWomX28N6Z3smAdKQ6sLGMv2wtaVNxADXp8uf98ge2wOkrJJ/rupICA0a7Rg1emfFgE5f6Mkvk+c/tbdsobEaDjjxFbvFEpZmO9+L7GH2k6PGK0Mfk2aSaj/Lz52VZTJo0KgpH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719277231; c=relaxed/simple; bh=w4WjO1E5zF9IHcpk+5zCvGcRvs+rmbzGg/TSib1t+D8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m58/WTJd8G7Bm5PQU3rJCpTnOcTL2bwi4GAeY/cmGnhlWucqqwAjnjMq8zhHjfYE6reKAMvL2ZzwvgjlDyeje52VOWQBAQZeutTvzDxyR/39ihZtfhKckx9nN39lGvVEGXsIYon/ZAWPh8rYRJyhDBVe40X7FVxtfFeTaV3qTlU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719277224; 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=kMu/4CNIdesYBvKsqPu8p0IJGH7lgsSNYqSdMz0nq5g=; b=hZaTRIkG7Z4lhOxVRyPp+hrrv+Pa1prxXvFa9J+olRIk5RxOX7+7e836GO9mDj3HoFuOE6 dS5dhhbryRailprvmAU08E8OQnXQW9/SKBF4+rWgC87zG2U7S6UaKA54WhJVeeURd4wb9g y/x7Uy1VlQhRPBiU73QkATiGJEIQFfs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571-ZcGRxq1rNbycwitz7nKLoA-1; Mon, 24 Jun 2024 21:00:22 -0400 X-MC-Unique: ZcGRxq1rNbycwitz7nKLoA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-795fb161698so990278285a.2 for ; Mon, 24 Jun 2024 18:00:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719277221; x=1719882021; 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=kMu/4CNIdesYBvKsqPu8p0IJGH7lgsSNYqSdMz0nq5g=; b=iwwMFVEqICJny++wDQgQzFEuqX+9ueI9ShlWow/eqJNFT/QG8TcoDI8ShzdLn0rrDg CjxlCeIXqc/6lhOFZF0clKDDaIXDMC4Bp1fb7IzpZX09qZ4ExB2DDs3TfuforlrCinak qadVv/qPw3TH0EyUHIvq/30+m/ArQNESlg3376V+ec2NIWyBY9W9G93YA0KeyIQM6Lpy AGu2YA6JsMvO5S1uUaUHi3ncJNYbTqjiEfuD8VkFajA89KSXhTe8ksSh/tE0IRFVWV6W tj3vV5aTOyi67BPW/PrXBG4l7GMN3gEg87J0eSwjldN6CSajdpa42VI95CrhRdLDiAWN AWzA== X-Gm-Message-State: AOJu0YxmiT7u9FPC0WSKKTfFt7/ofqPXt40kmhMp6QPNfYgJGQ7X6M+O ZLbwicGRwcGAmod2D97L6fdYt2RAQCDKoXQMtqt3V69KhZxJTNp/veC0Y+xDF96z1cXxXwK2pA3 XQGXUPFPriyQPLsQagYqhi5g+yygZOnWq1e2Vm9nXr80GiVuMu9MchnDjsZyn5L1ID0mXPA5l8J cO/lGXZzRHRlHyolIveaVs8b/dLAz0xojwH4PI X-Received: by 2002:a05:620a:4252:b0:79b:ea85:9f9f with SMTP id af79cd13be357-79bea85a042mr642870385a.2.1719277220729; Mon, 24 Jun 2024 18:00:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+DiTAg6SmGm632Lej9FZ6vZ/BqjQkbtlbME7fybgGZ77pJVb4YdgzqSjSPQYqMRVnAOuk1w== X-Received: by 2002:a05:620a:4252:b0:79b:ea85:9f9f with SMTP id af79cd13be357-79bea85a042mr642867985a.2.1719277220321; Mon, 24 Jun 2024 18:00:20 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce89d660sm359709585a.9.2024.06.24.18.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 18:00:19 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: decltype of by-ref capture proxy of ref [PR115504] Date: Mon, 24 Jun 2024 21:00:15 -0400 Message-ID: <20240625010015.122204-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.2.606.g9005149a4a MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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? -- >8 -- The capture proxy handling in finish_decltype_type added in r14-5330 was stripping the reference type of a capture proxy's captured variable, which is desirable for a by-value capture, but not for a by-ref capture (of a reference). PR c++/115504 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): For a by-reference capture proxy, don't strip the reference type (if any) of the captured variable. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto8.C: New test. --- gcc/cp/semantics.cc | 4 +++- gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 08f5f245e7d..b4f626924af 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12076,9 +12076,11 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, { if (is_normal_capture_proxy (expr)) { + bool by_ref = TYPE_REF_P (TREE_TYPE (expr)); expr = DECL_CAPTURED_VARIABLE (expr); type = TREE_TYPE (expr); - type = non_reference (type); + if (!by_ref) + type = non_reference (type); } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C new file mode 100644 index 00000000000..9a5e435f14f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C @@ -0,0 +1,11 @@ +// PR c++/115504 +// { dg-do compile { target c++14 } } + +void f(int& x) { + [&x]() { + decltype(auto) a = x; + using type = decltype(x); + using type = decltype(a); + using type = int&; // not 'int' + }; +}