From patchwork Mon Jul 16 21:24:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 171260 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 51D362C0116 for ; Tue, 17 Jul 2012 07:24:51 +1000 (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=1343078692; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=8oem42B ccbykyYHrFMhTuEqVrJs=; b=DA8wwKvhNftX0tABOwTEdCqlE7V36QoQJdKfN7b Hf2r7MSSLsHEh4padUFtA/Imxoq04Q8yKPA351TcUjyNvpxFORniG74M2d+sriaI jgZbemUPqzDyIC2kkcu0dHyu9udxJfbm7kJDlGhvh8LA74JayNRpSpfBgj7n+2Zl wgC4= 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:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=f/zah4yxS9KZ4cfGSZ5RSDkG1BJ/f8CRWzm5xGw+cUhNab9uCRr5hCnL9C9i6Z iQVErpZFHqul2yhRrbjqe8GCaX+MGHKp3LdCPcwrNg3vBbm8Oga0HQye5+LfkAKR i9tSib5qBgDAoB068QJ08mATRqt911obC6vPtkzYrodco=; Received: (qmail 30700 invoked by alias); 16 Jul 2012 21:24:47 -0000 Received: (qmail 30692 invoked by uid 22791); 16 Jul 2012 21:24:46 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Mon, 16 Jul 2012 21:24:27 +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 q6GLORC2003844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Jul 2012 17:24:27 -0400 Received: from [10.3.113.11] ([10.3.113.11]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6GLOQAF008559; Mon, 16 Jul 2012 17:24:26 -0400 Message-ID: <50048689.7090104@redhat.com> Date: Mon, 16 Jul 2012 17:24:25 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: gcc-patches List CC: Dodji Seketeli , Paolo Carlini Subject: C++ PATCH for better access violation diagnostic locations 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 While looking at Paolo's access sfinae patch, I noticed that we were giving poor locations for deferred access control errors. This patch fixes that by storing the location of the check to use again later. Tested x86_64-pc-linux-gnu, applying to trunk. commit f84991f247261f8e9d8c57115398f2fcd6ce9b62 Author: Jason Merrill Date: Mon Jul 16 17:08:11 2012 -0400 * cp-tree.h (struct deferred_access_check): Add location. * semantics.c (perform_access_checks): Use it. (perform_or_defer_access_check): Store it. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 10efa2a..59104e7 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5484,6 +5484,8 @@ typedef struct GTY(()) deferred_access_check { tree decl; /* The declaration that should be used in the error message. */ tree diag_decl; + /* The location of this access. */ + location_t loc; } deferred_access_check; DEF_VEC_O(deferred_access_check); DEF_VEC_ALLOC_O(deferred_access_check,gc); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index a32e48a..8110295 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -259,12 +259,18 @@ perform_access_checks (VEC (deferred_access_check,gc)* checks) { int i; deferred_access_check *chk; + location_t loc = input_location; if (!checks) return; FOR_EACH_VEC_ELT (deferred_access_check, checks, i, chk) - enforce_access (chk->binfo, chk->decl, chk->diag_decl); + { + input_location = chk->loc; + enforce_access (chk->binfo, chk->decl, chk->diag_decl); + } + + input_location = loc; } /* Perform the deferred access checks. @@ -334,6 +340,7 @@ perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl) new_access->binfo = binfo; new_access->decl = decl; new_access->diag_decl = diag_decl; + new_access->loc = input_location; } /* Used by build_over_call in LOOKUP_SPECULATIVE mode: return whether DECL diff --git a/gcc/testsuite/g++.dg/parse/access8.C b/gcc/testsuite/g++.dg/parse/access8.C index 45f4be7..205b7f2 100644 --- a/gcc/testsuite/g++.dg/parse/access8.C +++ b/gcc/testsuite/g++.dg/parse/access8.C @@ -5,8 +5,8 @@ class foo typedef int memfun; // { dg-error "private" } }; -template -struct fm_obj { }; // { dg-error "context" } +template // { dg-error "context" } +struct fm_obj { }; template // { dg-error "context" } struct S {}; diff --git a/gcc/testsuite/g++.dg/template/sfinae6_neg.C b/gcc/testsuite/g++.dg/template/sfinae6_neg.C index c238222..28adf73 100644 --- a/gcc/testsuite/g++.dg/template/sfinae6_neg.C +++ b/gcc/testsuite/g++.dg/template/sfinae6_neg.C @@ -14,14 +14,14 @@ template struct enable_if { }; template typename enable_if()(create_a(), create_a()), 1), yes_type>::type - check_is_callable2(type, type, type); + check_is_callable2(type, type, type); // { dg-error "within this context" } no_type check_is_callable2(...); template struct is_callable2 { - static const bool value = // { dg-error "within this context" } + static const bool value = (sizeof(check_is_callable2(type(), type(), type())) == sizeof(yes_type)); };