Error for use of field from anonymous struct or union should say "invalid use of...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 07:04:33 +0000 (07:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 07:04:33 +0000 (07:04 +0000)
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

lib/Sema/SemaExpr.cpp
test/SemaCXX/class.cpp

index 2429c75880e133766239f002d61aab0f037eef7a..4a0f2299dbdd4313ee998bb4acd4784d07a7f138 100644 (file)
@@ -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"
index 7c6a62f41e18c673ff82d304e025583bb531fbcd..52140cb0743d66a1f53fc4785264db7663c83774 100644 (file)
@@ -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}}
+}
+}