From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114825 invoked by alias); 16 Jan 2019 21:48:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 114603 invoked by uid 89); 16 Jan 2019 21:48:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Want, HX-Google-DKIM-Signature:sender, semantics.c, semanticsc X-HELO: mail-yw1-f47.google.com Received: from mail-yw1-f47.google.com (HELO mail-yw1-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Jan 2019 21:48:24 +0000 Received: by mail-yw1-f47.google.com with SMTP id d190so3051480ywd.12 for ; Wed, 16 Jan 2019 13:48:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=9AP3UcfCeCH4Q6Q7SUVo4Ms5L7YXmDT/wEpQIciYu2Q=; b=akDfseYSyoAWndX6dIoq9+dMG/CA2ZPqoUkNTD0tev7MzF0Fc/uikgFHGN//4ZGCWO tlCuwT1adu4RlDWHpORTQ8YgkklpV9quhh5JwEFVyq28H9HTzHMLIjvoxBQbNvwh4qki xspVy75JztRT3NBpmJH5oCuX1Rq1G4sny5VK0Ue9KIxEoLRPVhyRn2MkinMhvEfw3nIw rN/nGpkmlrnLUYGlcTniEnwCJMm38vuMHC18D1HOyowvnZVZGYrtzAKNTp7NQN/4EJJA e6dA/YfIBpro7zqRMTGi4Y5ZixeWFJGlSgoq33eeNh3qtcyQ5pseIPvwlz6TVBq8mTl1 MjJQ== Return-Path: Received: from ?IPv6:2620:10d:c0a3:1407:bc3c:5c5f:69bd:37a? ([2620:10d:c091:200::4:91d4]) by smtp.googlemail.com with ESMTPSA id s81sm2660641ywc.83.2019.01.16.13.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 13:48:11 -0800 (PST) Sender: Nathan Sidwell To: GCC Patches , Jason Merrill From: Nathan Sidwell Subject: [PR c++/86610] lambda captures in templates Message-ID: Date: Wed, 16 Jan 2019 21:48:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9611EDB698C704B234E51091" X-SW-Source: 2019-01/txt/msg00948.txt.bz2 This is a multi-part message in MIME format. --------------9611EDB698C704B234E51091 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 751 This PR reports a bug where we select a non-const operator function and then apply it to a const object. That's happening because the expression 'c[0]' is not dependent, so we figure end up resolving it. But the lambda capture logic doesn't capture 'c' at that point and we have a non-const qualified 'c'. At instantiation time we do the capture and the by-value lambda results in const-qualified captures. Jason, the orginal test in process_outer_var_ref looked a little funky -- why not just processing_template_decl? That would satisfy what the comment says it checking. Anyway changing the test to check DECL's type-dependency makes the right things happen, and a bootstrap passes. Could you review please. nathan -- Nathan Sidwell --------------9611EDB698C704B234E51091 Content-Type: text/x-patch; name="pr86610.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr86610.diff" Content-length: 1502 2019-01-16 Nathan Sidwell PR c++/86610 * semantics.c (process_outer_var_ref): Only skip dependent types in templates. PR c++/86610 * g++.dg/cpp0x/pr86610.C: New. Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 267983) +++ cp/semantics.c (working copy) @@ -3438,10 +3438,9 @@ process_outer_var_ref (tree decl, tsubst } /* In a lambda within a template, wait until instantiation - time to implicitly capture. */ + time to implicitly capture a dependent type. */ if (context == containing_function - && DECL_TEMPLATE_INFO (containing_function) - && uses_template_parms (DECL_TI_ARGS (containing_function))) + && dependent_type_p (TREE_TYPE (decl))) return decl; if (lambda_expr && VAR_P (decl) Index: testsuite/g++.dg/cpp0x/pr86610.C =================================================================== --- testsuite/g++.dg/cpp0x/pr86610.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr86610.C (working copy) @@ -0,0 +1,31 @@ +// { dg-do run { target c++11 } } +// PR c++86610 lambda capture inside template + +struct C +{ + int operator[](int) + { return 1; } + + int operator[](int) const + { return 0; } // Want this one +}; + +int q() +{ + C c; + return [=] { return c[0]; }(); +} + +template +int f() +{ + C c; + T d; + return [=] { return c[0]; }() + + [=] { return c[0] + d[0]; }(); +} + +int main() +{ + return q () + f(); +} --------------9611EDB698C704B234E51091--