From patchwork Wed Nov 15 13:15:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 838176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466859-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Voq5VPfd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ycPyP0pTGz9s81 for ; Thu, 16 Nov 2017 00:15:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=PShlDnTaL8KYzQz5r0coyIlua4W72u5MYtDsHn1Nd8lt8HVlFg UgViaZR+Qp6aoVo2Mt+FvUFQea3lcxWGhollGwOGsheH1GgM6XwAZE5SLOyrri5m 841DAuCBXX01n2sEj2t+eYVv0tq6+hrju7OLUuRocJGWzlRGoI4PUjvug= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=rKpDN6DHPqDQLpk4kbB7kMdNNZw=; b=Voq5VPfdB1ygIjaE64QJ LBMjDtgOM3qyd/gWXFD1hgUsMyUL0gunpt4++o83mV3gtd+tMSyOClhmOTE+8/Cn BJ7sLAPV3Hk/vJXUsdXqZzend2BpjX8LesnCgcVqHXqC1QvMItWL963Xh76NHsI9 sGsB85VqATl4qKUOk0sBI88= Received: (qmail 14961 invoked by alias); 15 Nov 2017 13:15:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 14947 invoked by uid 89); 15 Nov 2017 13:15:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=254740, Hx-languages-length:1521 X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Nov 2017 13:15:44 +0000 Received: by mail-yw0-f171.google.com with SMTP id k3so16366061ywk.8 for ; Wed, 15 Nov 2017 05:15:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=87U+j88vrC5ZUnKPDVYSVJhwMgiwSaXR6Rx3g8oTWoU=; b=uZidM8GaTHnc4RgWjaw3935yGAPZNg0UlnTre8HUIY5fSMIxoWcEY8PPWElQ6wkGIH 6YB1CkRIquyMYW/vQzObjcXDCIDLNJTad/xGymGS+JziYzW2KHsE7z6Wx5yLvutFC2rZ z4meHSMFjmXb05J1eLatzPDJ7lyDX9tsV18kTX888WB2g6Su+aKECTqmzonyKo3r/gll Ze5D7UPsegelC5mN2XLEsMbMoJmXNncNAlvW6EevpKQo7bBU9juPSr/LZl1rZf4G/eHS MKnD0uJlb5G901rkS9aVcyZTcdEozNDTw8bAhERh1ZntyJw9kSdkDlcCDobJYCVb4nFD P8IA== X-Gm-Message-State: AJaThX4GIi3Karh6WXsmMbydi8vJtjulH2DWkhE3RPNCBEyy4jyWmFfn jqZwP0Xehp3041LAfOU7yWQ= X-Google-Smtp-Source: AGs4zMZRSHS6xAXg8I0GRN6gP7z1auHOsVni0QZK28JfqcNdSRisgIY0T5EbTDEQjLI/Li7a/nI6gw== X-Received: by 10.13.217.145 with SMTP id b139mr2869222ywe.310.1510751742565; Wed, 15 Nov 2017 05:15:42 -0800 (PST) Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:ad4c]) by smtp.googlemail.com with ESMTPSA id l19sm9608019ywk.57.2017.11.15.05.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 05:15:41 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PR c++/81574] lambda capture of function reference Message-ID: <3813cfdf-4b72-728b-f6f7-a56f1c20126c@acm.org> Date: Wed, 15 Nov 2017 08:15:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 This patch fixes 81574. Even when the capture default is '=', a reference to a function is captured by reference. The init-capture case captures a pointer, via auto deduction machinery. AFAICT that's the correct behaviour. applying to trunk. nathan 2017-11-15 Nathan Sidwell PR c++/81574 * lambda.c (lambda_capture_field_type): Function references are always catured by reference. PR c++/81574 * g++.dg/cpp1y/pr81574.C: New. Index: cp/lambda.c =================================================================== --- cp/lambda.c (revision 254740) +++ cp/lambda.c (working copy) @@ -245,7 +245,8 @@ lambda_capture_field_type (tree expr, bo { type = non_reference (unlowered_expr_type (expr)); - if (!is_this && by_reference_p) + if (!is_this + && (by_reference_p || TREE_CODE (type) == FUNCTION_TYPE)) type = build_reference_type (type); } Index: testsuite/g++.dg/cpp1y/pr81574.C =================================================================== --- testsuite/g++.dg/cpp1y/pr81574.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr81574.C (working copy) @@ -0,0 +1,13 @@ +// { dg-do compile { target c++14 } } +// PR c++/81574 references to functions are captured by reference. + +// 8.1.5.2/10 +// For each entity captured by copy, ... an lvalue reference to the +// referenced function type if the entity is a reference to a function + +void f (void (&b)()) +{ + [=] { b; } (); + [=, b(f)] { b; } (); + [=, b(b)] { b; } (); +}