diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-05 01:13:04 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-05 01:13:04 +0000 |
commit | a85cf39786fffd6860a940523be01eb02a4935c0 (patch) | |
tree | 49e6b78abb519f6ddf1db6d7a31f3fbd66ea43c7 /test/SemaCXX | |
parent | 4fd05dc4062580acea72f8b8231fb0ea3ee49032 (diff) |
Improve diagnostics for invalid use of non-static members / this:
* s/nonstatic/non-static/ in the diagnostics, since the latter form outvoted
the former by 28-2 in our diagnostics.
* Fix the "use of member in static member function" diagnostic to correctly
detect this situation inside a block or lambda.
* Produce a more specific "invalid use of non-static member" diagnostic for
the case where a nested class member refers to a member of a
lexically-surrounding class.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX')
-rw-r--r-- | test/SemaCXX/class.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/default2.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/qual-id-test.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/this.cpp | 4 |
4 files changed, 14 insertions, 12 deletions
diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index e079d0cc17..ec82925fe4 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -7,16 +7,18 @@ public: static void sm() { sx = 0; - this->x = 0; // expected-error {{invalid use of 'this' outside of a nonstatic member function}} + this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}} x = 0; // expected-error {{invalid use of member 'x' in static member function}} } class NestedC { public: NestedC(int); - void m() { + void f() { sx = 0; - x = 0; // expected-error {{invalid use of nonstatic data member 'x'}} + x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}} + sm(); + m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}} } }; @@ -186,7 +188,7 @@ struct S { }; void f() { - S::c; // expected-error {{invalid use of nonstatic data member}} + S::c; // expected-error {{invalid use of non-static data member}} } } diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp index 20763229cf..16260449d4 100644 --- a/test/SemaCXX/default2.cpp +++ b/test/SemaCXX/default2.cpp @@ -28,7 +28,7 @@ void g(int x, int y = x); // expected-error {{default argument references parame void g2(int x, int y, int z = x + y); // expected-error {{default argument references parameter 'x'}} expected-error {{default argument references parameter 'y'}} class X { - void f(X* x = this); // expected-error{{invalid use of 'this' outside of a nonstatic member function}} + void f(X* x = this); // expected-error{{invalid use of 'this' outside of a non-static member function}} void g() { int f(X* x = this); // expected-error{{default argument references 'this'}} @@ -55,7 +55,7 @@ void C::h() { // C++ [dcl.fct.default]p9 struct Y { int a; - int mem1(int i = a); // expected-error{{invalid use of nonstatic data member 'a'}} + int mem1(int i = a); // expected-error{{invalid use of non-static data member 'a'}} int mem2(int i = b); // OK; use Y::b int mem3(int i); int mem4(int i); @@ -64,8 +64,8 @@ struct Y { int mem5(int i = b, // OK; use Y::b int j = c, // OK; use Y::Nested::c int k = j, // expected-error{{default argument references parameter 'j'}} - int l = a, // expected-error{{invalid use of nonstatic data member 'a'}} - Nested* self = this, // expected-error{{invalid use of 'this' outside of a nonstatic member function}} + int l = a, // expected-error{{invalid use of non-static data member 'a'}} + Nested* self = this, // expected-error{{invalid use of 'this' outside of a non-static member function}} int m); // expected-error{{missing default argument on parameter 'm'}} static int c; Nested(int i = 42); @@ -78,7 +78,7 @@ struct Y { int Y::mem3(int i = b) { return i; } // OK; use X::b -int Y::mem4(int i = a) // expected-error{{invalid use of nonstatic data member 'a'}} +int Y::mem4(int i = a) // expected-error{{invalid use of non-static data member 'a'}} { return i; } diff --git a/test/SemaCXX/qual-id-test.cpp b/test/SemaCXX/qual-id-test.cpp index e5c7306775..e43e6887c4 100644 --- a/test/SemaCXX/qual-id-test.cpp +++ b/test/SemaCXX/qual-id-test.cpp @@ -137,7 +137,7 @@ struct a { a a; -int a::sa = a.a; // expected-error {{invalid use of nonstatic data member 'a'}} +int a::sa = a.a; // expected-error {{invalid use of non-static data member 'a'}} namespace PR6645 { diff --git a/test/SemaCXX/this.cpp b/test/SemaCXX/this.cpp index 13158b93a4..27ee1e84a7 100644 --- a/test/SemaCXX/this.cpp +++ b/test/SemaCXX/this.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int x = this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}} +int x = this; // expected-error {{invalid use of 'this' outside of a non-static member function}} void f() { - int x = this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}} + int x = this; // expected-error {{invalid use of 'this' outside of a non-static member function}} } |