From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17886 invoked by alias); 25 Apr 2012 14:13:25 -0000 Received: (qmail 17869 invoked by uid 22791); 25 Apr 2012 14:13:19 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ob0-f175.google.com (HELO mail-ob0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Apr 2012 14:13:04 +0000 Received: by obceq6 with SMTP id eq6so155714obc.20 for ; Wed, 25 Apr 2012 07:13:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.164.69 with SMTP id yo5mr1906705obb.17.1335363183357; Wed, 25 Apr 2012 07:13:03 -0700 (PDT) Received: by 10.182.92.168 with HTTP; Wed, 25 Apr 2012 07:13:03 -0700 (PDT) In-Reply-To: References: Date: Wed, 25 Apr 2012 14:13:00 -0000 Message-ID: Subject: Re: [PATCH 10/13] Fix location for static class members From: Gabriel Dos Reis To: Dodji Seketeli Cc: GCC Patches , Tom Tromey , Jason Merrill Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg01588.txt.bz2 On Wed, Apr 25, 2012 at 8:55 AM, Dodji Seketeli wrote: > Consider the test case g++.dg/other/offsetof5.C: > > =A0 =A0#include > > =A0 =A0struct A > =A0 =A0{ > =A0 =A0 =A0char c; > =A0 =A0 =A0int &i; > =A0 =A0}; > > =A0 =A0int j =3D offsetof (A, i); =A0 =A0 =A0 =A0 =A0 =A0// { dg-warning = "invalid access|offsetof" } > > =A0 =A0template > =A0 =A0struct S > =A0 =A0{ > =A0 =A0 =A0T h; > =A0 =A0 =A0T &i; > =A0 =A0 =A0static const int j =3D offsetof (S, i); =A0 =A0 // { dg-warnin= g "invalid access|offsetof" } > =A0 =A0}; > > =A0 =A0int k =3D S::j; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// { dg-me= ssage "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). =A0And 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. =A0So 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. =A0But I had to adjust > g++.dg/template/sfinae6_neg.C for that. > > Tested on x86_64-unknown-linux-gnu against trunk. OK. > > gcc/cp > > =A0 =A0 =A0 =A0* decl.c (grokdeclarator): Use the location carried by the > =A0 =A0 =A0 =A0declarator for the DECL of the static class member. > > gcc/testsuite/ > > =A0 =A0 =A0 =A0* g++.dg/template/sfinae6_neg.C: Adjust. > --- > =A0gcc/cp/decl.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 | =A0 =A03 ++- > =A0gcc/testsuite/g++.dg/template/sfinae6_neg.C | =A0 =A04 ++-- > =A02 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, > =A0 =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* C++ allows static class members. =A0All= other work > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for this is done by grokfield. =A0*/ > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 decl =3D build_lang_decl (VAR_DECL, unquali= fied_id, type); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 decl =3D build_lang_decl_loc (declarator->i= d_loc, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 VAR_DECL, unqualified_id, type); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0set_linkage_for_static_data_member (decl); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Even if there is an in-class initializa= tion, DECL > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 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(...); > =A0template > =A0struct is_callable2 > =A0{ > - =A0static const bool value =3D > + =A0static const bool value =3D // { dg-error "within this context" } > =A0 =A0 (sizeof(check_is_callable2(type(), type(), type())) > - =A0 =A0 =3D=3D sizeof(yes_type)); // { dg-error "within this context" } > + =A0 =A0 =3D=3D sizeof(yes_type)); > =A0}; > > =A0#define JOIN( X, Y ) DO_JOIN( X, Y ) > -- > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Dodji