From patchwork Fri Dec 1 03:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 81070 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62432385828D for ; Fri, 1 Dec 2023 03:50: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 5D5343858D38 for ; Fri, 1 Dec 2023 03:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D5343858D38 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 5D5343858D38 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=1701402612; cv=none; b=lZ8yMHoABTg+qDschsgrmbpd0F8IMn1kTU5qpmDT9eLmWA/LhmF/eLVt04yj9c2B096aNeVXKdCZuO2GMJn2mbReQtFsGtZCW5qinrsu/u4SFDeFo7PZ0JNJHVGUyLWYEyaubPxlBT6oA6GPqwJ6B+wr/zGoNMvCkQmh6q19eoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701402612; c=relaxed/simple; bh=2l+UxAIJCfWVScYTNomiaLSvwDINNxsC+rV/p8PEHAM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VQdX1DzMNlrx0myFhxNHZg1Bx1QSBgpo6I76JhNJkg5W02GjV4D3F+Rqhhleydzq7hQ9eI01xLL2619c28U1h6faQu9yYN3HHcnxM/4cxJ4jMHaQaavVOoGYxHMEpf3b8qcKWckdM2Gm/ftXjIIxknH8UMocyEbgx1pm3oDbSfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701402611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/iQQXmD33Uyadizg5odOva12wS5BVVquAT8mnMmMWk=; b=jMDr5/gBwQ4aQju8147hvYcMgHfMSmkJt50TV+ONL77ToJHhYRyDq1+oWYw73Q/mQ2Otie doZUYNWkha51rg+inDWx7AmO+ok2SImCzcxUA8bxwlLVAUDcvHkyUWqzNJHymSZRk+Yw0z qWbzwmMuUFgErOZSYenjSW3rR3Igmds= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-m5n5vg3aMxGVJ4M3cVwZhg-1; Thu, 30 Nov 2023 22:50:09 -0500 X-MC-Unique: m5n5vg3aMxGVJ4M3cVwZhg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77dd463dfb0so215347985a.1 for ; Thu, 30 Nov 2023 19:50:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701402608; x=1702007408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C/iQQXmD33Uyadizg5odOva12wS5BVVquAT8mnMmMWk=; b=INfi3V2zyj9I7aPtil+1ZvMkO5cZlOrKW5mBNl0eMuZ9BIlZgJWVqvE0w/BrO1RsHK M5PBpegfM2cONAwhf6qTOFwGZA/Le53fYx2gTE5Laq703U/qGEmeZBe4uCvQzDCOfVGw u0IbqUWCC4+/WgfbpJAv9dumnC8R85VxzdK1R/WhMrGqU7N2yKN62BBIlFCSny7OQ0/z iOBKtmt6pjqyvzViD3AJqG+PVRZxOSpYWJ8KMIl9xL4U7g+BqtvJdzwPZis8i2FSUdRi D2R+bfKQy8vV47Fnhv00OYgDEwd1aZsBsg61RAozGPjXThbu6OObSvx3vmWu2GZYmpYZ AudQ== X-Gm-Message-State: AOJu0YyIBN9y30k7I8HZkJndGZlf1sQS491NWapKGa6QetYZD8EvPw5q MQXOfrOIob31etK/dxEOSZY0V+katOMcB5J6x+VnTYYYcUcqxiuLjOnL6rVPk0tMmkG3MtafYG7 RS88YlTBoEAnC3WV11ZDP8RF/lvOqw8rpQyczoJaODYKrwmiZTIK1FuvBWFEBN+b2Sxtpj/5dAQ == X-Received: by 2002:a05:620a:190e:b0:77d:89c4:1618 with SMTP id bj14-20020a05620a190e00b0077d89c41618mr23538540qkb.32.1701402608373; Thu, 30 Nov 2023 19:50:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCrVsEPrYjNXv/NoOgyPq2VLUdvSe2JKd1FCvQStI2PhHmX4ktH7Uoy+MXOamudHkDjfrtPw== X-Received: by 2002:a05:620a:190e:b0:77d:89c4:1618 with SMTP id bj14-20020a05620a190e00b0077d89c41618mr23538523qkb.32.1701402607879; Thu, 30 Nov 2023 19:50:07 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id i15-20020a05620a0a0f00b0077dc1476413sm1087544qka.131.2023.11.30.19.50.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 19:50:07 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: lambda capture and explicit object parm Date: Thu, 30 Nov 2023 22:50:03 -0500 Message-Id: <20231201035003.857697-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231130050027.700656-1-jason@redhat.com> References: <20231130050027.700656-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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, 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+patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- More adjustments to allow for explicit object parameters in lambdas. This has no practical effect until that patch goes in, but applying this separately seems reasonable. gcc/cp/ChangeLog: * semantics.cc (finish_non_static_data_member) (finish_decltype_type, capture_decltype): Handle deduced closure parameter. --- gcc/cp/semantics.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) base-commit: f2c52c0dfde581461959b0e2b423ad106aadf179 diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 36b57ac9524..fbbc18336a0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2262,6 +2262,16 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope, else if (PACK_EXPANSION_P (type)) /* Don't bother trying to represent this. */ type = NULL_TREE; + else if (WILDCARD_TYPE_P (TREE_TYPE (object))) + /* We don't know what the eventual quals will be, so punt until + instantiation time. + + This can happen when called from build_capture_proxy for an explicit + object lambda. It's a bit marginal to call this function in that + case, since this function is for references to members of 'this', + but the deduced type is required to be derived from the closure + type, so it works. */ + type = NULL_TREE; else { /* Set the cv qualifiers. */ @@ -11682,6 +11692,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, A::U doesn't require 'typename'. */ if (instantiation_dependent_uneval_expression_p (expr)) { + dependent: type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = expr; DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type) @@ -11856,7 +11867,11 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, if (outer_automatic_var_p (STRIP_REFERENCE_REF (expr)) && current_function_decl && LAMBDA_FUNCTION_P (current_function_decl)) - type = capture_decltype (STRIP_REFERENCE_REF (expr)); + { + type = capture_decltype (STRIP_REFERENCE_REF (expr)); + if (!type) + goto dependent; + } else if (error_operand_p (expr)) type = error_mark_node; else if (expr == current_class_ptr) @@ -12754,7 +12769,8 @@ apply_deduced_return_type (tree fco, tree return_type) /* DECL is a local variable or parameter from the surrounding scope of a lambda-expression. Returns the decltype for a use of the capture field - for DECL even if it hasn't been captured yet. */ + for DECL even if it hasn't been captured yet. Or NULL_TREE if we can't give + a correct answer at this point and we should build a DECLTYPE_TYPE. */ static tree capture_decltype (tree decl) @@ -12792,9 +12808,11 @@ capture_decltype (tree decl) if (!TYPE_REF_P (type)) { - int quals = cp_type_quals (type); tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl)); - gcc_checking_assert (!WILDCARD_TYPE_P (non_reference (obtype))); + if (WILDCARD_TYPE_P (non_reference (obtype))) + /* We don't know what the eventual obtype quals will be. */ + return NULL_TREE; + int quals = cp_type_quals (type); if (INDIRECT_TYPE_P (obtype)) quals |= cp_type_quals (TREE_TYPE (obtype)); type = cp_build_qualified_type (type, quals);