From patchwork Mon Sep 22 19:21:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 392129 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 44D081400BB for ; Tue, 23 Sep 2014 05:21:33 +1000 (EST) 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=R77DX49ekgLuIDWDYV0ZSDpYUnY4fh60EAXqn3ii/WXF41 8XYOaeyuz7Cvytsu4lJzXGlYbiizcw6T8LxOHB8Al5/Ke55QRqe7o888M3VdirXF ZNymdHFzlYdwT2vGvW/a5kcs+lFXY2zyRVrhPKhyo8BlSl1CEI4eIOB3AEcgg= 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=IaVb0dew7iNM9UDOJmG4yOEjB8M=; b=F/61A2uXTV2EI3+qfz7S Y0v94Po/XdvGY7IqdDEm+THE4rtU7uLcLmcciO2qHbO8ZGOz2Mse8sZCs4rKAKVq CpwJENJbhYzj5uH2RNNIUce49g08kqdVsyiTeWvuYS58Z+DVnp3ZL8tjpsvTUJAQ BxZdO5P/Fh67jUsitOTOvLQ= Received: (qmail 17040 invoked by alias); 22 Sep 2014 19:21: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 17028 invoked by uid 89); 22 Sep 2014 19:21:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS 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, 22 Sep 2014 19:21:24 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8MJLMB7009450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 22 Sep 2014 15:21:22 -0400 Received: from [10.10.116.30] ([10.10.116.30]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8MJLLQu015535 for ; Mon, 22 Sep 2014 15:21:22 -0400 Message-ID: <542076B1.40806@redhat.com> Date: Mon, 22 Sep 2014 15:21:21 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to tweak invalid non-static data member diagnostic Adjusting this diagnostic to conform to our convention of having only one error message plus notes. Tested x86_64-pc-linux-gnu, applying to trunk. commit 99ef5c20fe8566fbfbe14e085f765d2c3f05b252 Author: Jason Merrill Date: Mon Sep 22 13:43:18 2014 -0400 * semantics.c (finish_non_static_data_member): In diagnostic, give error at point of use and note at point of declaration. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1d81028..6e04e5e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1692,10 +1692,10 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) { if (current_function_decl && DECL_STATIC_FUNCTION_P (current_function_decl)) - error ("invalid use of member %q+D in static member function", decl); + error ("invalid use of member %qD in static member function", decl); else - error ("invalid use of non-static data member %q+D", decl); - error ("from this location"); + error ("invalid use of non-static data member %qD", decl); + inform (DECL_SOURCE_LOCATION (decl), "declared here"); return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C index 9c76d34..fa8a6e6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C @@ -3,7 +3,7 @@ class Klass { - unsigned int local; // { dg-error "non-static" } + unsigned int local; public: bool dostuff(); }; @@ -11,7 +11,7 @@ public: bool Klass::dostuff() { auto f = []() -> bool { - if (local & 1) { return true; } // { dg-error "not captured|this location" } + if (local & 1) { return true; } // { dg-error "not captured|non-static" } return false; }; } diff --git a/gcc/testsuite/g++.dg/lookup/scoped8.C b/gcc/testsuite/g++.dg/lookup/scoped8.C index 2764f75..c5645ee 100644 --- a/gcc/testsuite/g++.dg/lookup/scoped8.C +++ b/gcc/testsuite/g++.dg/lookup/scoped8.C @@ -7,12 +7,12 @@ struct A { - int i; // { dg-error "non-static" } + int i; // { dg-message "" } }; template struct B { - int foo() { return A::i; } // { dg-error "this location" } + int foo() { return A::i; } // { dg-error "non-static" } }; template struct B<0>; diff --git a/gcc/testsuite/g++.dg/other/ptrmem2.C b/gcc/testsuite/g++.dg/other/ptrmem2.C index d267df1..335f492 100644 --- a/gcc/testsuite/g++.dg/other/ptrmem2.C +++ b/gcc/testsuite/g++.dg/other/ptrmem2.C @@ -8,7 +8,7 @@ struct D { - int &m; // { dg-error "invalid use of non-static data member" "" } + int &m; // { dg-message "" } static int &s; int Foo (); @@ -29,7 +29,7 @@ int D::Foo () int Foo () { f1( &D::m); // { dg-error "cannot create pointer to ref" "" } - f1( &(D::m)); // { dg-error "from this location" "" } + f1( &(D::m)); // { dg-error "non-static" } f2( &D::s); // ok f2( &(D::s)); // ok return 0; diff --git a/gcc/testsuite/g++.dg/template/dependent-expr5.C b/gcc/testsuite/g++.dg/template/dependent-expr5.C index ecb7a67..8d14553 100644 --- a/gcc/testsuite/g++.dg/template/dependent-expr5.C +++ b/gcc/testsuite/g++.dg/template/dependent-expr5.C @@ -18,7 +18,7 @@ template void bindb(F (T::*f)(void)) {} // { dg-message "note" struct foo { static int baist; - int bait; // { dg-error "non-static data member" } + int bait; // { dg-message "" } void barf (); static void barf (int); @@ -31,7 +31,7 @@ struct foo { bar() { bind (&baist); bind (&foo::baist); - bind (&bait); // { dg-error "from this location" } + bind (&bait); // { dg-error "non-static data member" } bind (&foo::bait); bind (&baikst); @@ -83,7 +83,7 @@ struct foo { barT() { bind (&baist); bind (&foo::baist); - bind (&bait); // { dg-error "from this location" } + bind (&bait); // { dg-error "non-static data member" } bind (&foo::bait); bind (&baikst); diff --git a/gcc/testsuite/g++.dg/template/error15.C b/gcc/testsuite/g++.dg/template/error15.C index b7c7bc8..8693658 100644 --- a/gcc/testsuite/g++.dg/template/error15.C +++ b/gcc/testsuite/g++.dg/template/error15.C @@ -9,9 +9,9 @@ template class B { protected: - A a; // { dg-error "" } + A a; // { dg-message "" } - void f(const A * a1 = &a); // { dg-error "this location" } + void f(const A * a1 = &a); // { dg-error "non-static" } void g(void); }; diff --git a/gcc/testsuite/g++.dg/template/error42.C b/gcc/testsuite/g++.dg/template/error42.C index 0d651e3..3c66ed0 100644 --- a/gcc/testsuite/g++.dg/template/error42.C +++ b/gcc/testsuite/g++.dg/template/error42.C @@ -3,18 +3,18 @@ template struct A { - int i; // { dg-error "invalid use of non-static data member" } + int i; // { dg-message "" } friend void foo () { - int x[i]; // { dg-error "from this location" } + int x[i]; // { dg-error "non-static data member" } } }; struct B { - int j; // { dg-error "invalid use of non-static data member" } + int j; // { dg-message "" } friend int bar () { - return j; // { dg-error "from this location" } + return j; // { dg-error "non-static data member" } } }; diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/crash18.C b/gcc/testsuite/g++.old-deja/g++.brendan/crash18.C index 3119f02..aa605ef 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/crash18.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/crash18.C @@ -8,11 +8,11 @@ public: // Friend functions so that v == x works as does x == v works friend int operator==(void *v, const Pix& x) // { dg-message "previously" } - { return v == index; } // { dg-error "from this location" } + { return v == index; } // { dg-error "non-static" } // ??? should be operator!= friend int operator==(void *v, const Pix& x) // { dg-error "redefinition" } { return v != index; } private: // friend class List; - element *index; // { dg-error "invalid use of non-static data member" } + element *index; // { dg-message "" } }; diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/nest1.C b/gcc/testsuite/g++.old-deja/g++.brendan/nest1.C index 842b2f6..07ba778 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/nest1.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/nest1.C @@ -3,12 +3,12 @@ int x; class enclose { public: - int x; // { dg-error "non-static" } + int x; // { dg-message "" } class inner { public: void f (int i) { - x = i;// { dg-error "" } .* + x = i;// { dg-error "non-static" } .* } }; }; diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/static1.C b/gcc/testsuite/g++.old-deja/g++.brendan/static1.C index cb83923..cba5551 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/static1.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/static1.C @@ -1,4 +1,4 @@ // { dg-do assemble } // GROUPS passed static -class A { public: int a; };// { dg-error "" } .* +class A { public: int a; };// { dg-message "" } .* void foo7 () { A::a = 3; }// { dg-error "" } .* diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900213_01.C b/gcc/testsuite/g++.old-deja/g++.bugs/900213_01.C index e7feb94..9a16a74 100644 --- a/gcc/testsuite/g++.old-deja/g++.bugs/900213_01.C +++ b/gcc/testsuite/g++.old-deja/g++.bugs/900213_01.C @@ -12,7 +12,7 @@ // keywords: non-static members, member pointers, scope resolution struct struct0 { - int struct0_data_member_0; /* { dg-error "" } gets error from below */ + int struct0_data_member_0; /* { dg-message "" } gets error from below */ int struct0_function_member_0 (); }; diff --git a/gcc/testsuite/g++.old-deja/g++.gb/scope06.C b/gcc/testsuite/g++.old-deja/g++.gb/scope06.C index cbcc4fd..658cbe1 100644 --- a/gcc/testsuite/g++.old-deja/g++.gb/scope06.C +++ b/gcc/testsuite/g++.old-deja/g++.gb/scope06.C @@ -1,16 +1,14 @@ // { dg-do assemble } -// { dg-prune-output "non-static data member initializers" } // GROUPS passed gb scope struct C { struct D { int x; void foo (); }; - const int Ok = 0; // { dg-error "" } initialization forbidden + const int Ok = 0; // { dg-error "" "" { target { ! c++11 } } } initialization forbidden }; void C::D::foo () { - // { dg-prune-output "from this location" } - x = Ok; + x = Ok; // { dg-error "non-static" } } diff --git a/gcc/testsuite/g++.old-deja/g++.law/cvt11.C b/gcc/testsuite/g++.old-deja/g++.law/cvt11.C index 53dd1e9..383cded 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/cvt11.C +++ b/gcc/testsuite/g++.old-deja/g++.law/cvt11.C @@ -6,15 +6,11 @@ // Message-Id: <9211101908.AA13557@tera.com> // Subject: type cast of qualified const member breaks g++2.3.1 -// Ignore extra errors in C++0x mode. -// { dg-prune-output "non-static data member initializers" } -// { dg-prune-output "from this location" } -// { dg-prune-output "uninitialized" } #include class Thing{ private: int x; - public: const int N = -1; // { dg-error "" } bad initialization +public: const int N = -1; // { dg-error "" "" { target { ! c++11 } } } bad initialization Thing(int y); }; @@ -23,10 +19,10 @@ class Bar{ public: void doit(void); }; void Bar::doit(void) { int i, j; - i = Thing::N; + i = Thing::N; // { dg-error "non-static" } printf("i = %d\n", i); - j = (int)Thing::N; + j = (int)Thing::N; // { dg-error "non-static" } printf("i = %d\n", j); } Thing::Thing(int y) { x = y; }