From patchwork Wed Apr 25 13:55:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 154929 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 DFBB2B6EE7 for ; Wed, 25 Apr 2012 23:55:43 +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=1335966944; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=iKwat6Spdrg3I3jxKtuRjhsTRH0=; b=ouM7Hlxt0nlliJ3hOzCZnv5I7Ov6WI9Ah1uHSTl7M5YKcANQUqJj9VSd4DAeQl sXDzUWQqYsdVPCOGrYYWk7Zpe5J+G5fav2jYd1WC6u0FILtC2ZatA1lstwe3CJAH ffmtgdJ9tOeHyvIwfUiYgh9ie7AqO5/vI/QYd/dsXYTPw= 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:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=WXqlsLm2+oitC+RkNfI1SDEQP2xY/Y2n76d1WUDTY015cOm4egsMYN8BsW9m+g BIWmTFNVbaCWerHu+iUHGq6R2iob3zvEgHvx70lZuhB6tyt2sjFSx05epVm5ry9F q3baMwiy5y71jp9OOqNWVdYwfQ5u5FvaYygWNa0R6JM7g=; Received: (qmail 6479 invoked by alias); 25 Apr 2012 13:55:39 -0000 Received: (qmail 6464 invoked by uid 22791); 25 Apr 2012 13:55:38 -0000 X-SWARE-Spam-Status: No, hits=-5.9 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; Wed, 25 Apr 2012 13:55:24 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3PDtOe6021782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Apr 2012 09:55:24 -0400 Received: from localhost (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3PDtMEj004437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 25 Apr 2012 09:55:23 -0400 Received: by localhost (Postfix, from userid 500) id 1A0B129C046; Wed, 25 Apr 2012 15:55:22 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Tom Tromey , Jason Merrill , Gabriel Dos Reis Subject: [PATCH 10/13] Fix location for static class members References: X-URL: http://www.redhat.com Date: Wed, 25 Apr 2012 15:55:21 +0200 In-Reply-To: (Dodji Seketeli's message of "Tue, 10 Apr 2012 16:53:12 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 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 Consider the test case g++.dg/other/offsetof5.C: #include struct A { char c; int &i; }; int j = offsetof (A, i); // { dg-warning "invalid access|offsetof" } template struct S { T h; T &i; static const int j = offsetof (S, i); // { dg-warning "invalid access|offsetof" } }; int k = S::j; // { dg-message "required from here" } The second warning (that involves the instantiation of the S template) is not emitted when -ftrack-macro-expansion is on. This is because during the instantiation of the member j of S template, the location that is used for the warning is the one for the DECL j (set by instantiate_decl). And that location is inaccurately set to the locus of 'offsetof', which is a macro defined in a system header, so it's discarded by the diagnostics machinery. Note that when we reach the point where we emit the warning in build_class_member_access_expr offsetof expression has long been folded, so we cannot use e.g, the location of the ')' token that would have been in the source code. So I believe the location of 'j' is the best we can get at this point. The patch below sets the location of the DECL for 'j' to what I believe is its precise location; with that, the test case passes with and without -ftrack-macro-expansion. But I had to adjust g++.dg/template/sfinae6_neg.C for that. Tested on x86_64-unknown-linux-gnu against trunk. gcc/cp * decl.c (grokdeclarator): Use the location carried by the declarator for the DECL of the static class member. gcc/testsuite/ * g++.dg/template/sfinae6_neg.C: Adjust. --- gcc/cp/decl.c | 3 ++- gcc/testsuite/g++.dg/template/sfinae6_neg.C | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 28c7cee..40818a3 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10267,7 +10267,8 @@ grokdeclarator (const cp_declarator *declarator, { /* C++ allows static class members. All other work for this is done by grokfield. */ - decl = build_lang_decl (VAR_DECL, unqualified_id, type); + decl = build_lang_decl_loc (declarator->id_loc, + VAR_DECL, unqualified_id, type); set_linkage_for_static_data_member (decl); /* Even if there is an in-class initialization, DECL is considered undefined until an out-of-class diff --git a/gcc/testsuite/g++.dg/template/sfinae6_neg.C b/gcc/testsuite/g++.dg/template/sfinae6_neg.C index d4be5dd..9b7bdfd1 100644 --- a/gcc/testsuite/g++.dg/template/sfinae6_neg.C +++ b/gcc/testsuite/g++.dg/template/sfinae6_neg.C @@ -21,9 +21,9 @@ no_type check_is_callable2(...); template struct is_callable2 { - static const bool value = + static const bool value = // { dg-error "within this context" } (sizeof(check_is_callable2(type(), type(), type())) - == sizeof(yes_type)); // { dg-error "within this context" } + == sizeof(yes_type)); }; #define JOIN( X, Y ) DO_JOIN( X, Y )