From patchwork Fri Feb 22 19:16:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 222678 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 C11FD2C02A7 for ; Sat, 23 Feb 2013 09:24:10 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362176651; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=dghEQS2 b2e2tLHfqJAJbx9lcZAw=; b=e8c8PO3gpoIj6Wxb8hMzxurqb39jD9HmU78zEYt TKOvPQ5EB6mL3xz1kOlSlo7Z0bMQ+Bcg2T+J6Bhdoyl0Ug/4ogIzxiubOPjC766X 9oAUcXM5OePtbWxj97OlMmG6hR+84JVrAksK2PUAqy2dRrU+tykYovFGaqsGNwIW QZbQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Nu4OKmStirly0yFCUVhTY2HynH23sUAdpeVTovAcd+sR2t8O8M8VHWnb8vkIdG VLiZdp3czY8efEHzOWSnfPCz6/nTBVqnaZLhRre/dq90m940+TpYkZZ87ewLVYb2 d3LhY/H9h6oC4XxGuW6zq1mwSlOj0YIrh3I9E97UN2dPM=; Received: (qmail 1447 invoked by alias); 22 Feb 2013 22:23:46 -0000 Received: (qmail 1397 invoked by uid 22791); 22 Feb 2013 22:23:45 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, DATE_IN_PAST_03_06, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Fri, 22 Feb 2013 22:23:33 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1MMNXf6026454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Feb 2013 17:23:33 -0500 Received: from [10.3.113.106] (ovpn-113-106.phx2.redhat.com [10.3.113.106]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1MMNWXr028951 for ; Fri, 22 Feb 2013 17:23:32 -0500 Message-ID: <5127C3FB.1030405@redhat.com> Date: Fri, 22 Feb 2013 14:16:11 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20100101 Thunderbird/20.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56359 (wrong access error with function template) 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 We need to be careful not to do any access checking on the actual arguments to the function when we're pushed into the context of the function being instantiated. Tested x86_64-pc-linux-gnu, applying to trunk. commit 7498f299d97da75ce3ab30d0626818a143fbaab9 Author: Jason Merrill Date: Fri Feb 22 10:44:03 2013 -0500 PR c++/56359 * call.c (can_convert_arg): Discard access checks. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 25dfd51..7c41421 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8765,11 +8765,18 @@ can_convert_arg (tree to, tree from, tree arg, int flags, /* Get the high-water mark for the CONVERSION_OBSTACK. */ p = conversion_obstack_alloc (0); + /* We want to discard any access checks done for this test, + as we might not be in the appropriate access context and + we'll do the check again when we actually perform the + conversion. */ + push_deferring_access_checks (dk_deferred); t = implicit_conversion (to, from, arg, /*c_cast_p=*/false, flags, complain); ok_p = (t && !t->bad_p); + /* Discard the access checks now. */ + pop_deferring_access_checks (); /* Free all the conversions we allocated. */ obstack_free (&conversion_obstack, p); diff --git a/gcc/testsuite/g++.dg/template/access25.C b/gcc/testsuite/g++.dg/template/access25.C new file mode 100644 index 0000000..e882a70 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access25.C @@ -0,0 +1,20 @@ +// PR c++/56359 + +typedef int (*InvocationCallback) (const int &); + +template < typename target_t > +void SetPrototypeMethod (target_t, const char *, InvocationCallback); + +class A +{ + void Initialize (); +protected: + static int Stop (const int &); + void Stop (); // comment out to make the bug disappear. +}; + +void +A::Initialize () +{ + SetPrototypeMethod (0, "stop", A::Stop); +}