From patchwork Tue Nov 7 19:52:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1861277 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=aJUNxkTl; 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 4SPzR43kN9z1yRL for ; Wed, 8 Nov 2023 06:53:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB25E3858421 for ; Tue, 7 Nov 2023 19:52:59 +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 779DD3858D1E for ; Tue, 7 Nov 2023 19:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 779DD3858D1E 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 779DD3858D1E 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=1699386768; cv=none; b=FVybrmm9Aqhj/TwqSQBK6P8zVnAZ7p7ITq15TFIwtv97Xr9eRWcKwpCX9C5ITGtZemaf1T0QGvYiioFUQXNknzE0GBt9STMSw1SzdrCCmQfcBdbHORl4lJEq9Q76Q0ZBGRw6G9Dd0cbT1yjnqUNw5flVXLQMnHbIzxRZFOnodaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699386768; c=relaxed/simple; bh=62Gxgqq6I7xG24mAHGM7FfrzbQlKV5rdWwTkn2uPVZY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pU/pOujNNorh9XtwZEdOwJwxa4pEaBmKBppNVtL5kDukbXHqiWA9/lYpnyGKJu/2qH9cxMNqRIv0xRxmG6H7pW3M/cBUQ22CNVqe7xpOYnO+W8iaEhT2xRdFzfcnC4JjyF3EkNTDWCaqaUdA3VVkM7Fr0QDnDur3U2jwbv8AKDs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699386765; 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=bXbNmoPFPB6ddojRnGNJj8fx6tQwaOid7cckmHkyQHQ=; b=aJUNxkTlBzuvtpTL05KqXtJduW2cd0XlIw/zUE+A0TDWX/difqIrVKJqbc1DRO9qR3CiYv t3DZZHk4S+GolEIYqqaKXPaDodcYhhCxqMm8yR3TO6SzIEnhJzHBRhGXuq88MPF4qSoheo gANiNBLvse2r7p/v+HJ5xHFVkKuNuCY= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-ToJVqpSbOyaVNNjQznhI6g-1; Tue, 07 Nov 2023 14:52:43 -0500 X-MC-Unique: ToJVqpSbOyaVNNjQznhI6g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-66d062708b0so77795356d6.1 for ; Tue, 07 Nov 2023 11:52:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699386760; x=1699991560; 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=bXbNmoPFPB6ddojRnGNJj8fx6tQwaOid7cckmHkyQHQ=; b=FNEfLd3gXnNqP09exCBOQZwfDDzYCZlbEIFP9lALu+8lbyXH8CUHeSJiqB07mqzlN7 dZkE7OJ+q8HRGf2BXbVMOUCsGrykB9Sl4RZcS9rdVuhEAr0KEq75EQleHlaBcVasqdYR sIdTPYnp5JRA3SLsx78GJB9mpo2N87sieu0jweunv0C6I8znPP9GhO1pR4YCavfVnRNO QhVlA5vYAftM6OY8nnyQBoN/YT+BQA4FN+xoqsZwV45ke8aaJJlYiM2O3g1lATza7Bfx USZzMXJAaqytyUouAT1FkZAlW8+n/5/C2DeVI8mxoyf5ezSaI9q91Aw6OLES+/gRC7+V pROw== X-Gm-Message-State: AOJu0YwWNfR6pzSLD+8k7cNHFenNyWO3ZWuIDOvF69NLL0g4g2FC5mhp gjBm8o5hV4CouGlpEQTgDy6LssW2cM5Bcj4sS4rFDcc4IYA+nJ9JQoLg1RgMfYxitMYJ1wpx3Og NWIb5H/oydhG1eAwF1tV7g4i4whNizMuhXVV1TIpr2OiuIBc6rLVsNAv9bdGQg0DseVCg4edJ94 Y= X-Received: by 2002:a05:6214:234f:b0:675:7328:854a with SMTP id hu15-20020a056214234f00b006757328854amr17970114qvb.62.1699386760625; Tue, 07 Nov 2023 11:52:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOPLm0FIh8tNXsn8YSJ9XSvIi3z9rUvcZUAVH2FXsC41oLcVzO4lZ48gbayKWhhzwkK+eAnQ== X-Received: by 2002:a05:6214:234f:b0:675:7328:854a with SMTP id hu15-20020a056214234f00b006757328854amr17970089qvb.62.1699386760063; Tue, 07 Nov 2023 11:52:40 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id d4-20020a0ce704000000b0066d04196c39sm219034qvn.81.2023.11.07.11.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 11:52:39 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: decltype of capture proxy [PR79378, PR96917] Date: Tue, 7 Nov 2023 14:52:37 -0500 Message-ID: <20231107195237.1658753-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc0.23.g8be77c5de6 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_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 -- We usually don't see capture proxies in finish_decltype_type because process_outer_var_ref is a no-op inside an unevaluated context and so a use of a capture inside decltype refers directly to the captured variable. But we can still see a capture proxy during decltype(auto) deduction and for decltype of an init-capture, which suggests we need to handle capture proxies specially within finish_decltype_type (since they're always implicitly const). This patch adds such handling. PR c++/79378 PR c++/96917 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Handle an id-expression naming a capture proxy specially. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto7.C: New test. * g++.dg/cpp1y/lambda-init20.C: New test. --- gcc/cp/semantics.cc | 28 +++++++++-- gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C | 53 +++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-init20.C | 22 +++++++++ 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init20.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4059e74bdb7..f583dedd6cf 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11643,12 +11643,30 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, /* Fall through for fields that aren't bitfields. */ gcc_fallthrough (); - case FUNCTION_DECL: case VAR_DECL: - case CONST_DECL: - case PARM_DECL: - case RESULT_DECL: - case TEMPLATE_PARM_INDEX: + if (is_capture_proxy (expr)) + { + if (is_normal_capture_proxy (expr)) + { + expr = DECL_CAPTURED_VARIABLE (expr); + type = TREE_TYPE (expr); + type = non_reference (type); + } + else + { + expr = DECL_VALUE_EXPR (expr); + gcc_assert (TREE_CODE (expr) == COMPONENT_REF); + expr = TREE_OPERAND (expr, 1); + type = TREE_TYPE (expr); + } + break; + } + /* Fall through. */ + case FUNCTION_DECL: + case CONST_DECL: + case PARM_DECL: + case RESULT_DECL: + case TEMPLATE_PARM_INDEX: expr = mark_type_use (expr); type = TREE_TYPE (expr); if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr)) diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C new file mode 100644 index 00000000000..a37b9db38d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto7.C @@ -0,0 +1,53 @@ +// PR c++/96917 +// { dg-do compile { target c++14 } } + +int main() { + int x = 0; + int y = 0; + const int cx = 0; + const int cy = 0; + + [x, &y, cx, &cy] { + decltype(auto) a = x; + using ty1 = int; + using ty1 = decltype(x); + using ty1 = decltype(a); + + decltype(auto) b = y; + using ty2 = int; + using ty2 = decltype(y); + using ty2 = decltype(b); + + decltype(auto) ca = cx; + using ty3 = const int; + using ty3 = decltype(cx); + using ty3 = decltype(ca); + + decltype(auto) cb = cy; + using ty4 = const int; + using ty4 = decltype(cy); + using ty4 = decltype(cb); + }; + + [x=x, &y=y, cx=cx, &cy=cy] { + decltype(auto) a = x; + using ty1 = int; + using ty1 = decltype(x); + using ty1 = decltype(a); + + decltype(auto) b = y; + using ty2 = int&; + using ty2 = decltype(y); + using ty2 = decltype(b); + + decltype(auto) ca = cx; + using ty3 = int; + using ty3 = decltype(cx); + using ty3 = decltype(ca); + + decltype(auto) cb = cy; + using ty4 = const int&; + using ty4 = decltype(cy); + using ty4 = decltype(cb); + }; +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C new file mode 100644 index 00000000000..a06b77a664d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init20.C @@ -0,0 +1,22 @@ +// PR c++/79378 +// { dg-do compile { target c++14 } } + +int main() { + int x = 0; + [x=x, &r=x] { + using ty1 = int; + using ty1 = decltype(x); + + using ty2 = int&; + using ty2 = decltype(r); + }; + + const int cx = 0; + [x=cx, &r=cx] { + using ty1 = int; + using ty1 = decltype(x); + + using ty2 = const int&; + using ty2 = decltype(r); + }; +}