From patchwork Tue Nov 14 16:10:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1863738 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=buqeUiek; 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 4SVB9k3JGQz1yR8 for ; Wed, 15 Nov 2023 03:11:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F11CC38582AD for ; Tue, 14 Nov 2023 16:11:03 +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 4D5973858D32 for ; Tue, 14 Nov 2023 16:10:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D5973858D32 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 4D5973858D32 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=1699978251; cv=none; b=SYoLJX0tqnI6enX8WKNQB309sFk9KQlr8my838CJa3bjyNLS1Kux8tJJNiBmgR0LgPUbDCqVdNTZ17tb6K3+1QBM+pTHQm674HhgFdqmGDescopTqnYV+2hKYG2Mej8OUvEu6pwS/XWhvAapKOpwCDhfNnAZqHD19F++hyfkdY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699978251; c=relaxed/simple; bh=5BhLHnC7akHvMdKJkBd0Wz/THCk0fr3KcaXCxv2F9jE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fnC3TfM3X1ciguolVvL23d3w1CL6PXGpMkLMp3L4fqxHfUqUo0GLJ47jMYfeIuVjy1MITWG6P4ahD3cZR/NA1TMQqMUHboEHuoSZ57cmdD6RFO6hexBzaXSMnh/P1tnhbZOC6hZH5fyoB0eQ7oY+tVHdUhRZNDxe9aOlQSwdzho= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699978250; 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=nNLlI5rCTJzIf7ceeavaDlrv5nxsHuxZsS7zG2HuKeI=; b=buqeUiekcjZq73kWGV266GDoLt6KdfDydjQTepDi1AJ2K5hLy/B8VMHWO573i0V0hpUgwQ rQcaexQ4TKKbNk+aZYF3ZEx8pnUaRMBd8fTpHOYzq3eUC+y4cLtVtXBqZISInWNep0Kz01 X2ipjP4DoRf4aw/2P6cEHIJ/lRngUHA= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-553Zof1XPWy8u6SGpDgGgA-1; Tue, 14 Nov 2023 11:10:48 -0500 X-MC-Unique: 553Zof1XPWy8u6SGpDgGgA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-41ea8e21785so100404131cf.1 for ; Tue, 14 Nov 2023 08:10:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699978247; x=1700583047; 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=nNLlI5rCTJzIf7ceeavaDlrv5nxsHuxZsS7zG2HuKeI=; b=s9tR3BgcmgR7ZNm+xFu3imvyL6vLI5+UJJSqdX03RQRuHeicgcQK1t+xSwDCmqgUbT LCIlHwj4vtMd+8uMF0SXT6ZPWJjMqYgY5Bca+VF7jcy4HVePf2AiHNOSf4NSus9w0LoP p/ZbagA6AsCUbV/yTDwAutBjscmNH4tt3q4OowPf5qYvRfoFwd6PKxNZVdYtg08U3zLx OitmwrDiw1pfOMi2KRZGDeJXR/czaTVKe6mwU2CTKxp/iMLGI+3bLPAoBSdBMsDKGDXm FMPnbDsN812BBul8zdVJVEChxtoHhb6GVoLGHmxKPBFz2kYWKdRtl9Ztyr4blp4dtwIa qHCQ== X-Gm-Message-State: AOJu0YzojI87Ty71+utDm7NvztF19JTeidTrik55R9I33U0tNN+m9aag xTUe5ifdpN4KRZTLeh9+Ukxs/WFKXSQJloneiUbYWD0npoJCfaw8spIgQsJyD8ne1oyvTiCcRy/ R8CKHLViY/1qhK6cDnec1SYNMlFnOKPEPY7xzT25+23wBRecl68wEtYX6TXqKsuxvLbO1p/1TTk A= X-Received: by 2002:ac8:5dd4:0:b0:41c:c588:b821 with SMTP id e20-20020ac85dd4000000b0041cc588b821mr3904319qtx.25.1699978247075; Tue, 14 Nov 2023 08:10:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0KcMUWr/PD5ljwP4Pm7UsFCnXEPrHi3TuZNJWC7fA2bFQvLWzqDPaQKL6OeP6n1G6Jeo4Fg== X-Received: by 2002:ac8:5dd4:0:b0:41c:c588:b821 with SMTP id e20-20020ac85dd4000000b0041cc588b821mr3904281qtx.25.1699978246729; Tue, 14 Nov 2023 08:10:46 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id x16-20020ac85390000000b004198d026be6sm2846664qtp.35.2023.11.14.08.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 08:10:46 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: decltype of (non-captured variable) [PR83167] Date: Tue, 14 Nov 2023 11:10:44 -0500 Message-ID: <20231114161044.985367-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 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 -- For decltype((x)) within a lambda where x is not captured, we dubiously require that the lambda has a capture default, unlike for decltype(x). This patch fixes this inconsistency; I couldn't find a justification for it in the standard. PR c++/83167 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): If capture_decltype returns NULL_TREE, fall back to the ordinary code path. (capture_decltype): Return NULL_TREE if the lambda has no capture-default. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-decltype4.C: New test. --- gcc/cp/semantics.cc | 6 +++--- .../g++.dg/cpp0x/lambda/lambda-decltype4.C | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8090c71809f..6fdd6c45972 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11732,7 +11732,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, /* If the expression is just "this", we want the cv-unqualified pointer for the "this" type. */ type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); - else + + if (!type) { /* Otherwise, where T is the type of e, if e is an lvalue, decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ @@ -12639,8 +12640,7 @@ capture_decltype (tree decl) switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) { case CPLD_NONE: - error ("%qD is not captured", decl); - return error_mark_node; + return NULL_TREE; case CPLD_COPY: type = TREE_TYPE (decl); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C new file mode 100644 index 00000000000..0062d7b8672 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C @@ -0,0 +1,15 @@ +// PR c++/83167 +// { dg-do compile { target c++11 } } + +int main() { + int x; + const int y = 42; + + [] { + using ty1 = decltype((x)); + using ty1 = int&; + + using ty2 = decltype((y)); + using ty2 = const int&; + }; +}