From: Argyrios Kyrtzidis Date: Mon, 31 Jan 2011 07:04:33 +0000 (+0000) Subject: Error for use of field from anonymous struct or union should say "invalid use of... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ad5df132a0bcb3f6975362901270be5bf60dc56;p=clang 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 --- 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()) { + if (R.getAsSingle() || R.getAsSingle()) { if (CXXMethodDecl *MD = dyn_cast(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}} +} +}