[cfe-commits] r84370 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaCXX/member-expr.cpp

Douglas Gregor dgregor at apple.com
Sat Oct 17 15:37:54 PDT 2009


Author: dgregor
Date: Sat Oct 17 17:37:54 2009
New Revision: 84370

URL: http://llvm.org/viewvc/llvm-project?rev=84370&view=rev
Log:
Fix a crash with qualified member access into a non-type, from Sean Hunt!

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/member-expr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=84370&r1=84369&r2=84370&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Oct 17 17:37:54 2009
@@ -383,6 +383,8 @@
   "lookup in the object type %0 refers here">;
 def note_ambig_member_ref_scope : Note<
   "lookup from the current scope refers here">;
+def err_qualified_member_nonclass : Error<
+  "qualified member access refers to a member in %0">;
 
 // C++ class members
 def err_storageclass_invalid_for_member : Error<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=84370&r1=84369&r2=84370&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 17 17:37:54 2009
@@ -2184,6 +2184,12 @@
       // If the member name was a qualified-id, look into the
       // nested-name-specifier.
       DC = computeDeclContext(*SS, false);
+      
+      if (!isa<TypeDecl>(DC)) {
+        Diag(MemberLoc, diag::err_qualified_member_nonclass)
+          << DC << SS->getRange();
+        return ExprError();
+      }
 
       // FIXME: If DC is not computable, we should build a
       // CXXUnresolvedMemberExpr.

Modified: cfe/trunk/test/SemaCXX/member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-expr.cpp?rev=84370&r1=84369&r2=84370&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/member-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-expr.cpp Sat Oct 17 17:37:54 2009
@@ -31,3 +31,14 @@
   return b->f0->f0; // expected-error{{member reference base type 'struct A *()' is not a structure or union}} \
   // expected-note{{perhaps you meant to call this function}}
 }
+
+int i;
+
+namespace C {
+  int i;
+}
+
+void test2(X *xp) {
+  xp->::i = 7; // expected-error{{qualified member access refers to a member in the global namespace}}
+  xp->C::i = 7; // expected-error{{qualified member access refers to a member in namespace 'C'}}
+}





More information about the cfe-commits mailing list