diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-31 07:04:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-31 07:04:33 +0000 |
commit | 6ad5df132a0bcb3f6975362901270be5bf60dc56 (patch) | |
tree | 1150cd808eca4bdfb94c98fcaf9911c56dabd32a | |
parent | 0413db4a26b0a1577b75c2979b0eb21f3490d17a (diff) |
Error for use of field from anonymous struct or union should say "invalid use of nonstatic data member"
not "call to non-static member function without an object argument".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124576 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/class.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2429c75880..4a0f2299db 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1154,7 +1154,7 @@ static void DiagnoseInstanceReference(Sema &SemaRef, SourceRange Range(Loc); if (SS.isSet()) Range.setBegin(SS.getRange().getBegin()); - if (R.getAsSingle<FieldDecl>()) { + if (R.getAsSingle<FieldDecl>() || R.getAsSingle<IndirectFieldDecl>()) { if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(SemaRef.CurContext)) { if (MD->isStatic()) { // "invalid use of member 'x' in static member function" diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index 7c6a62f41e..52140cb074 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -176,3 +176,15 @@ namespace rdar8367341 { static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' is a C++0x extension}} expected-error {{in-class initializer is not a constant expression}} }; } + +namespace with_anon { +struct S { + union { + char c; + }; +}; + +void f() { + S::c; // expected-error {{invalid use of nonstatic data member}} +} +} |