[cfe-commits] r90343 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp

John McCall rjmccall at apple.com
Wed Dec 2 12:26:01 PST 2009


Author: rjmccall
Date: Wed Dec  2 14:26:00 2009
New Revision: 90343

URL: http://llvm.org/viewvc/llvm-project?rev=90343&view=rev
Log:
Use a more rigorous definition of 'class member'.  I don't have any evidence
that this was causing a problem, but it could have.


Added:
    cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Dec  2 14:26:00 2009
@@ -732,11 +732,23 @@
   return true;
 }
                                   
-static bool IsInstanceMember(NamedDecl *D) {
-  if (isa<EnumConstantDecl>(D))
-    return false;
+/// Determines if this a C++ class member.
+static bool IsClassMember(NamedDecl *D) {
+  DeclContext *DC = D->getDeclContext();
+
+  // C++0x [class.mem]p1:
+  //   The enumerators of an unscoped enumeration defined in
+  //   the class are members of the class.
+  // FIXME: support C++0x scoped enumerations.
+  if (isa<EnumDecl>(DC))
+    DC = DC->getParent();
 
-  assert(isa<CXXRecordDecl>(D->getDeclContext()) &&
+  return DC->isRecord();
+}
+
+/// Determines if this is an instance member of a class.
+static bool IsInstanceMember(NamedDecl *D) {
+  assert(IsClassMember(D) &&
          "checking whether non-member is instance member");
 
   if (isa<FieldDecl>(D)) return true;
@@ -798,7 +810,7 @@
 /// not be caught until template-instantiation.
 static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
                                             const LookupResult &R) {
-  assert(!R.empty() && isa<CXXRecordDecl>((*R.begin())->getDeclContext()));
+  assert(!R.empty() && IsClassMember(*R.begin()));
 
   bool isStaticContext =
     (!isa<CXXMethodDecl>(SemaRef.CurContext) ||
@@ -1010,7 +1022,7 @@
   //   class member access expression.
   // But note that &SomeClass::foo is grammatically distinct, even
   // though we don't parse it that way.
-  if (!R.empty() && (*R.begin())->getDeclContext()->isRecord()) {
+  if (!R.empty() && IsClassMember(*R.begin())) {
     bool isAbstractMemberPointer = (isAddressOfOperand && !SS.isEmpty());
 
     if (!isAbstractMemberPointer) {
@@ -1274,7 +1286,7 @@
     //     -- a declaration of a class member
     // Since using decls preserve this property, we check this on the
     // original decl.
-    if (D->getDeclContext()->isRecord())
+    if (IsClassMember(D))
       return false;
 
     // C++0x [basic.lookup.argdep]p3:

Added: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp?rev=90343&view=auto

==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp (added)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp Wed Dec  2 14:26:00 2009
@@ -0,0 +1,20 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// FIXME: embellish
+
+namespace test0 {
+  namespace A {
+    class Foo {
+    };
+
+    void foo(const Foo &foo);
+  }
+
+  class Test {
+    enum E { foo = 0 };
+
+    void test() {
+      foo(A::Foo()); // expected-error {{not a function}}
+    }
+  };
+}





More information about the cfe-commits mailing list