From patchwork Mon Mar 9 19:51:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 448190 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 716051400F1 for ; Tue, 10 Mar 2015 06:51:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XXlL1yXj; dkim-adsp=none (unprotected policy); 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=ExdBtbDz0jAkBqlG2bengADauH/K1HNhIob0MygUN5e4+E LODiXEN4rtyhUNstkCwSAtjBEX8/ba/useJI8PI19Yv9Y5vDlSUyvt2VJiI2Ukxg rzlIgbCUqWKlYgsN5504amHlhRjTzS2J0NPEgKbe8c3frS3qnTQ+q7DS3DrCM= 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=2w5RnTNa0diO77/S/m0sym5NJd4=; b=XXlL1yXj9r+BvqsEsPAz bjMGl8bPkFkP3elMzJL2HUk8ewytXYrOCca1Xj/YA5/RoQWVxxSe8qUufDSnqK8E 0mZLi6lMxqwWSVn6iQClEEIgctELsx8R7CuYcHxKPHlQL5mHuHsAFRikNkdNYUxj zwHb87Xh73ZjkA5Vx/kPY2s= Received: (qmail 32091 invoked by alias); 9 Mar 2015 19:51:26 -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 32078 invoked by uid 89); 9 Mar 2015 19:51:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham 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; Mon, 09 Mar 2015 19:51:25 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t29JpNPZ023973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Mar 2015 15:51:23 -0400 Received: from [10.3.112.83] (ovpn-112-83.phx2.redhat.com [10.3.112.83]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t29JpMwP008708 for ; Mon, 9 Mar 2015 15:51:23 -0400 Message-ID: <54FDF9B9.1020909@redhat.com> Date: Mon, 09 Mar 2015 15:51:21 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/65339 (ICE with lambda) In this testcase we were crashing while trying to build up a copy constructor call within the thunk for the function pointer conversion operator, because we try to resolve 'this' and there is no 'this' in a static member function. Fixed by avoiding that resolution when we're calling a constructor, which never implicitly uses 'this'. Tested x86_64-pc-linux-gnu, applying to trunk. commit 63ca18a58a5fab2281872955d71bbeb44956a835 Author: Jason Merrill Date: Fri Mar 6 14:45:55 2015 -0500 PR c++/65339 * call.c: Don't call maybe_resolve_dummy when calling a constructor. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 2b15185..fdd8436 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8020,7 +8020,11 @@ build_new_method_call_1 (tree instance, tree fns, vec **args, that would be captured if the call turns out to be to a non-static member function. Do not actually capture it at this point. */ - first_mem_arg = maybe_resolve_dummy (instance, false); + if (DECL_CONSTRUCTOR_P (fn)) + /* Constructors don't use the enclosing 'this'. */ + first_mem_arg = instance; + else + first_mem_arg = maybe_resolve_dummy (instance, false); /* Get the high-water mark for the CONVERSION_OBSTACK. */ p = conversion_obstack_alloc (0); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv9.C new file mode 100644 index 0000000..d7955fd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv9.C @@ -0,0 +1,27 @@ +// PR c++/65339 +// { dg-do compile { target c++11 } } + +class FuncWrapper { +public: + template void callfunc(Func f) + { + f(); + } +}; + +class Object { + int field; +public: + void Method(); + Object() { field = 555; } + Object(const Object&) { __builtin_abort(); } +}; + +void Object::Method () +{ + FuncWrapper wrap; + wrap.callfunc(*[]() + { + return Object(); + }); +}