From patchwork Fri Feb 13 14:51:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Azzarone X-Patchwork-Id: 439515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 9E1CF1402D7 for ; Sat, 14 Feb 2015 01:51:52 +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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=ryfJsbk3NO3kUWGli5uUkIVqBQ9WnYLycl7wQk1l/Ji3Ub 98Ghz3ruV9EzPFYSDaGzowWPnF8KmHtBjEIx3zXiqmr3MDTZ5PzCTdiBxZ0oeSiQ CX2EA9NlhzvbXs0cfBtur3QEQLNghu1Q2Rr360F35VOjhvaDjUFwhdk0PvGYs= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=eniITw4mFXxjn+xP914WiFQY8lY=; b=nbKGOprcUkrc8p5r2zYw wh8+p362x88FTIZY160G/7utx5i1VYX+2Iuu3mUMDXRi0NHOkZ7PNDrYzZXu0OhC mAHwlfX+X3747mZuoXMfIn2S+mrdMqmVcTGd2ufRl7LTfENqg3B+HfaUHB8WuRGJ CFZJiyMgHW1s/CICIuz8sKY= Received: (qmail 25859 invoked by alias); 13 Feb 2015 14:51:44 -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 25843 invoked by uid 89); 13 Feb 2015 14:51:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-la0-f43.google.com Received: from mail-la0-f43.google.com (HELO mail-la0-f43.google.com) (209.85.215.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 13 Feb 2015 14:51:43 +0000 Received: by labgf13 with SMTP id gf13so16826899lab.9 for ; Fri, 13 Feb 2015 06:51:40 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.112.173.42 with SMTP id bh10mr8410870lbc.103.1423839099919; Fri, 13 Feb 2015 06:51:39 -0800 (PST) Received: by 10.114.181.33 with HTTP; Fri, 13 Feb 2015 06:51:39 -0800 (PST) Date: Fri, 13 Feb 2015 15:51:39 +0100 Message-ID: Subject: PATCH for c++/64948 From: Andrea Azzarone To: gcc-patches@gcc.gnu.org X-IsSubscribed: yes Hi all, this patch try to fix PR c++/64948 (Lambda reference capture initialization in template function creates segmentation fault). 2015-2-13 Andrea Azzarone PR c++/64948 * lambda.c (add_capture) Do not consider as rvalues all expressions involving template parameters. Index: gcc/cp/lambda.c =================================================================== --- gcc/cp/lambda.c (revision 220454) +++ gcc/cp/lambda.c (working copy) @@ -506,7 +506,7 @@ add_capture (tree lambda, tree id, tree if (by_reference_p) { type = build_reference_type (type); - if (!real_lvalue_p (initializer)) + if (TREE_TYPE (initializer) && !real_lvalue_p (initializer)) error ("cannot capture %qE by reference", initializer); } else Index: gcc/testsuite/g++.dg/cpp1y/lambda-init13.C =================================================================== --- gcc/testsuite/g++.dg/cpp1y/lambda-init13.C (revision 0) +++ gcc/testsuite/g++.dg/cpp1y/lambda-init13.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/64948 +// { dg-do compile { target c++14 } } + +template +void foo(T t) { + [&i = t.begin()]() {}; +} + +int main() { +} Index: gcc/testsuite/g++.dg/cpp1y/lambda-init14.C =================================================================== --- gcc/testsuite/g++.dg/cpp1y/lambda-init14.C (revision 0) +++ gcc/testsuite/g++.dg/cpp1y/lambda-init14.C (working copy) @@ -0,0 +1,16 @@ +// PR c++/64948 +// { dg-do compile { target c++14 } } + +template +void foo(T t) { + [&i = t.begin()]() {}; // { dg-error "invalid initialization" } +} + +struct X { + int begin() { return 0; } +}; + +int main() { + X x; + foo(x); +}