From patchwork Fri Jun 19 17:58:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 486869 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 596D21401E7 for ; Sat, 20 Jun 2015 03:59:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LaaBrLzz; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=VjN8frWIknSt4g413YmZLL5Bu6os1wA8LA5rH19EZcnZsT OmPtt/SAFuNHiqHItGuFCXVTW67mY2KmrjdU4OHqQYPN7/RnL5AGEbMsSKH9ka3S 8Iaa+ZDXiIZJMeJ1zX6M5zPHkk7v41/3wNoAVts18nMqYJzxaXQEJ64FbVoYw= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=SNP03U5WdlHzHTNX21uPKWOnRYs=; b=LaaBrLzzr8KDRozf1qmX aFRgFi0tYePwEK+15MMyDc2RAvw2yJfXNz07XB2+K5tM85Sz065T7riEVB9r+ZCn 6z8VzreD4TRjsn57zWGXkLtZwuL3DilRBNjhQLoI8m7Mo3Jc8vw3CNQmeou66aGp PVHn2Qw3tLf3f/djqOpLec8= Received: (qmail 90523 invoked by alias); 19 Jun 2015 17:58:53 -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 90505 invoked by uid 89); 19 Jun 2015 17:58:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 19 Jun 2015 17:58:52 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 05CE719F974 for ; Fri, 19 Jun 2015 17:58:50 +0000 (UTC) Received: from [10.10.116.27] ([10.10.116.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5JHwo6s032419 for ; Fri, 19 Jun 2015 13:58:50 -0400 Message-ID: <55845857.6020908@redhat.com> Date: Fri, 19 Jun 2015 13:58:47 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/65843 (error with multiple use of captured variable in lambda) Here, in template substitution we were calling process_outer_var_ref for both references to the outer variable without doing a name lookup to see if there is a local binding. If we add the local capture to local_specializations, we will find that when we come to the second reference. Tested x86_64-pc-linux-gnu, applying to trunk and 5. commit 3d5c19d59298d326eec727209f1bb28570c4a1cf Author: Jason Merrill Date: Fri Jun 19 10:34:04 2015 -0400 PR c++/65843 * pt.c (tsubst_copy_and_build): Register a capture proxy in local_specializations. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8377d21..5179827 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15684,7 +15684,11 @@ tsubst_copy_and_build (tree t, r = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); } else if (outer_automatic_var_p (r)) - r = process_outer_var_ref (r, complain); + { + r = process_outer_var_ref (r, complain); + if (is_capture_proxy (r)) + register_local_specialization (r, t); + } if (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE) /* If the original type was a reference, we'll be wrapped in diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C new file mode 100644 index 0000000..a35060b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C @@ -0,0 +1,14 @@ +// PR c++/65843 +// { dg-do compile { target c++11 } } + +template +void test(T b) +{ + const int a = b; + [&] () { return a, a; }(); +} + +int main() { + test(1); + return 0; +}