Commit 6863c41a by Jason Merrill Committed by Jason Merrill

semantics.c (finish_non_static_data_member): In diagnostic, give error at point…

semantics.c (finish_non_static_data_member): In diagnostic, give error at point of use and note at point of declaration.

	* semantics.c (finish_non_static_data_member): In diagnostic, give
	error at point of use and note at point of declaration.

From-SVN: r215479
parent a546927c
2014-09-22 Jason Merrill <jason@redhat.com> 2014-09-22 Jason Merrill <jason@redhat.com>
* semantics.c (finish_non_static_data_member): In diagnostic, give
error at point of use and note at point of declaration.
PR c++/63320 PR c++/63320
PR c++/60463 PR c++/60463
PR c++/60755 PR c++/60755
......
...@@ -1692,10 +1692,10 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) ...@@ -1692,10 +1692,10 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
{ {
if (current_function_decl if (current_function_decl
&& DECL_STATIC_FUNCTION_P (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 else
error ("invalid use of non-static data member %q+D", decl); error ("invalid use of non-static data member %qD", decl);
error ("from this location"); inform (DECL_SOURCE_LOCATION (decl), "declared here");
return error_mark_node; return error_mark_node;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
class Klass class Klass
{ {
unsigned int local; // { dg-error "non-static" } unsigned int local;
public: public:
bool dostuff(); bool dostuff();
}; };
...@@ -11,7 +11,7 @@ public: ...@@ -11,7 +11,7 @@ public:
bool Klass::dostuff() bool Klass::dostuff()
{ {
auto f = []() -> bool { 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; return false;
}; };
} }
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
struct A struct A
{ {
int i; // { dg-error "non-static" } int i; // { dg-message "" }
}; };
template <int> struct B template <int> struct B
{ {
int foo() { return A::i; } // { dg-error "this location" } int foo() { return A::i; } // { dg-error "non-static" }
}; };
template struct B<0>; template struct B<0>;
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
struct D { struct D {
int &m; // { dg-error "invalid use of non-static data member" "" } int &m; // { dg-message "" }
static int &s; static int &s;
int Foo (); int Foo ();
...@@ -29,7 +29,7 @@ int D::Foo () ...@@ -29,7 +29,7 @@ int D::Foo ()
int Foo () int Foo ()
{ {
f1( &D::m); // { dg-error "cannot create pointer to ref" "" } 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
f2( &(D::s)); // ok f2( &(D::s)); // ok
return 0; return 0;
......
...@@ -18,7 +18,7 @@ template<class F, class T> void bindb(F (T::*f)(void)) {} // { dg-message "note" ...@@ -18,7 +18,7 @@ template<class F, class T> void bindb(F (T::*f)(void)) {} // { dg-message "note"
struct foo { struct foo {
static int baist; static int baist;
int bait; // { dg-error "non-static data member" } int bait; // { dg-message "" }
void barf (); void barf ();
static void barf (int); static void barf (int);
...@@ -31,7 +31,7 @@ struct foo { ...@@ -31,7 +31,7 @@ struct foo {
bar() { bar() {
bind (&baist); bind (&baist);
bind (&foo::baist); bind (&foo::baist);
bind (&bait); // { dg-error "from this location" } bind (&bait); // { dg-error "non-static data member" }
bind (&foo::bait); bind (&foo::bait);
bind (&baikst); bind (&baikst);
...@@ -83,7 +83,7 @@ struct foo { ...@@ -83,7 +83,7 @@ struct foo {
barT() { barT() {
bind (&baist); bind (&baist);
bind (&foo::baist); bind (&foo::baist);
bind (&bait); // { dg-error "from this location" } bind (&bait); // { dg-error "non-static data member" }
bind (&foo::bait); bind (&foo::bait);
bind (&baikst); bind (&baikst);
......
...@@ -9,9 +9,9 @@ template <class T> ...@@ -9,9 +9,9 @@ template <class T>
class B { class B {
protected: protected:
A<T> a; // { dg-error "" } A<T> a; // { dg-message "" }
void f(const A<T> * a1 = &a); // { dg-error "this location" } void f(const A<T> * a1 = &a); // { dg-error "non-static" }
void g(void); void g(void);
}; };
......
...@@ -3,18 +3,18 @@ ...@@ -3,18 +3,18 @@
template <int> struct A template <int> struct A
{ {
int i; // { dg-error "invalid use of non-static data member" } int i; // { dg-message "" }
friend void foo () friend void foo ()
{ {
int x[i]; // { dg-error "from this location" } int x[i]; // { dg-error "non-static data member" }
} }
}; };
struct B struct B
{ {
int j; // { dg-error "invalid use of non-static data member" } int j; // { dg-message "" }
friend int bar () friend int bar ()
{ {
return j; // { dg-error "from this location" } return j; // { dg-error "non-static data member" }
} }
}; };
...@@ -8,11 +8,11 @@ public: ...@@ -8,11 +8,11 @@ public:
// Friend functions so that v == x works as does x == v works // Friend functions so that v == x works as does x == v works
friend int operator==(void *v, const Pix& x) // { dg-message "previously" } 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!= // ??? should be operator!=
friend int operator==(void *v, const Pix& x) // { dg-error "redefinition" } friend int operator==(void *v, const Pix& x) // { dg-error "redefinition" }
{ return v != index; } { return v != index; }
private: private:
// friend class List<T>; // friend class List<T>;
element *index; // { dg-error "invalid use of non-static data member" } element *index; // { dg-message "" }
}; };
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
int x; int x;
class enclose { class enclose {
public: public:
int x; // { dg-error "non-static" } int x; // { dg-message "" }
class inner { class inner {
public: public:
void f (int i) { void f (int i) {
x = i;// { dg-error "" } .* x = i;// { dg-error "non-static" } .*
} }
}; };
}; };
......
// { dg-do assemble } // { dg-do assemble }
// GROUPS passed static // GROUPS passed static
class A { public: int a; };// { dg-error "" } .* class A { public: int a; };// { dg-message "" } .*
void foo7 () { A::a = 3; }// { dg-error "" } .* void foo7 () { A::a = 3; }// { dg-error "" } .*
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// keywords: non-static members, member pointers, scope resolution // keywords: non-static members, member pointers, scope resolution
struct struct0 { 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 (); int struct0_function_member_0 ();
}; };
......
// { dg-do assemble } // { dg-do assemble }
// { dg-prune-output "non-static data member initializers" }
// GROUPS passed gb scope // GROUPS passed gb scope
struct C { struct C {
struct D { struct D {
int x; int x;
void foo (); 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 () void C::D::foo ()
{ {
// { dg-prune-output "from this location" } x = Ok; // { dg-error "non-static" }
x = Ok;
} }
...@@ -6,15 +6,11 @@ ...@@ -6,15 +6,11 @@
// Message-Id: <9211101908.AA13557@tera.com> // Message-Id: <9211101908.AA13557@tera.com>
// Subject: type cast of qualified const member breaks g++2.3.1 // 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 <stdio.h> #include <stdio.h>
class Thing{ class Thing{
private: int x; 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); Thing(int y);
}; };
...@@ -23,10 +19,10 @@ class Bar{ public: void doit(void); }; ...@@ -23,10 +19,10 @@ class Bar{ public: void doit(void); };
void Bar::doit(void) void Bar::doit(void)
{ {
int i, j; int i, j;
i = Thing::N; i = Thing::N; // { dg-error "non-static" }
printf("i = %d\n", i); printf("i = %d\n", i);
j = (int)Thing::N; j = (int)Thing::N; // { dg-error "non-static" }
printf("i = %d\n", j); printf("i = %d\n", j);
} }
Thing::Thing(int y) { x = y; } Thing::Thing(int y) { x = y; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment