[cfe-commits] r124576 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/class.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Jan 30 23:04:33 PST 2011


Author: akirtzidis
Date: Mon Jan 31 01:04:33 2011
New Revision: 124576

URL: http://llvm.org/viewvc/llvm-project?rev=124576&view=rev
Log:
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".

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/class.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=124576&r1=124575&r2=124576&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jan 31 01:04:33 2011
@@ -1154,7 +1154,7 @@
   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"

Modified: cfe/trunk/test/SemaCXX/class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class.cpp?rev=124576&r1=124575&r2=124576&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/class.cpp (original)
+++ cfe/trunk/test/SemaCXX/class.cpp Mon Jan 31 01:04:33 2011
@@ -176,3 +176,15 @@
     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}}
+}
+}





More information about the cfe-commits mailing list