From patchwork Wed May 25 14:27:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 97352 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]) by ozlabs.org (Postfix) with SMTP id 56263B6F97 for ; Thu, 26 May 2011 00:27:17 +1000 (EST) Received: (qmail 14386 invoked by alias); 25 May 2011 14:27:15 -0000 Received: (qmail 14378 invoked by uid 22791); 25 May 2011 14:27:15 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 May 2011 14:27:01 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4PER1j7008594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 May 2011 10:27:01 -0400 Received: from [127.0.0.1] (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4PER0in009523 for ; Wed, 25 May 2011 10:27:01 -0400 Message-ID: <4DDD11B4.70600@redhat.com> Date: Wed, 25 May 2011 10:27:00 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/45080 (lambda conversion in templates) 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 The lambda conversion operator isn't added to CLASSTYPE_DECL_LIST, so it got lost on instantiation. But since we cut some corners building it up to reduce runtime overhead, it's easier to just add it again at instantiation time. Tested x86_64-pc-linux-gnu, applying to trunk. commit 3b93aba17af31a772141a871c3299250dbbda714 Author: Jason Merrill Date: Wed May 25 01:21:49 2011 -0400 PR c++/45080 * pt.c (instantiate_class_template_1): Call maybe_add_lambda_conv_op. * semantics.c (lambda_function): Check COMPLETE_OR_OPEN_TYPE_P. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index fc84314..bb4515b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8566,6 +8566,9 @@ instantiate_class_template_1 (tree type) } } + if (CLASSTYPE_LAMBDA_EXPR (type)) + maybe_add_lambda_conv_op (type); + /* Set the file and line number information to whatever is given for the class itself. This puts error messages involving generated implicit functions at a predictable point, and the same point diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 50f25f0..55ad117 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8145,7 +8145,8 @@ lambda_function (tree lambda) type = lambda; gcc_assert (LAMBDA_TYPE_P (type)); /* Don't let debug_tree cause instantiation. */ - if (CLASSTYPE_TEMPLATE_INSTANTIATION (type) && !COMPLETE_TYPE_P (type)) + if (CLASSTYPE_TEMPLATE_INSTANTIATION (type) + && !COMPLETE_OR_OPEN_TYPE_P (type)) return NULL_TREE; lambda = lookup_member (type, ansi_opname (CALL_EXPR), /*protect=*/0, /*want_type=*/false); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv5.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv5.C new file mode 100644 index 0000000..53d8e99 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv5.C @@ -0,0 +1,15 @@ +// PR c++/45080 +// { dg-options -std=c++0x } + +typedef void(*pfn)(); + +template +void f() +{ + pfn fn = []{}; +} + +void test() +{ + f(); +}