[cfe-commits] r61079 - in /cfe/trunk: lib/Sema/SemaCXXScopeSpec.cpp test/SemaCXX/nested-name-spec.cpp

Douglas Gregor dgregor at apple.com
Mon Dec 15 22:37:47 PST 2008


Author: dgregor
Date: Tue Dec 16 00:37:47 2008
New Revision: 61079

URL: http://llvm.org/viewvc/llvm-project?rev=61079&view=rev
Log:
Partial fix for qualified name lookup, such that the lookup of N in
N::X only skips those entities specified in C++ [basic.lookup.qual]p1.

Note that both EDG and GCC currently get this wrong. EDG has confirmed
that the bug will be fixed in a future version.

Modified:
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
    cfe/trunk/test/SemaCXX/nested-name-spec.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Dec 16 00:37:47 2008
@@ -28,8 +28,8 @@
       DeclContext::lookup_const_iterator I, E;
       for (llvm::tie(I, E) = LookupCtx->lookup(Context, Name); I != E; ++I) {
        IdIsUndeclared = false;
-       if (((*I)->getIdentifierNamespace() & Decl::IDNS_Tag) && 
-           !isa<EnumDecl>(*I))
+       if (((*I)->getIdentifierNamespace() & Decl::IDNS_Tag) || 
+           isa<TypedefDecl>(*I))
          return *I;
       }
 
@@ -56,12 +56,10 @@
     // not a class-name or namespace-name, the program is ill-formed.
 
     for (; I != E; ++I) {
-      if (TypedefDecl *TD = dyn_cast<TypedefDecl>(*I)) {
-        if (TD->getUnderlyingType()->isRecordType())
-          break;
-        continue;
+      if (isa<TypedefDecl>(*I)) {
+        break;
       }
-      if (((*I)->getIdentifierNamespace()&Decl::IDNS_Tag) && !isa<EnumDecl>(*I))
+      if (((*I)->getIdentifierNamespace() & Decl::IDNS_Tag))
         break;    
     }
 
@@ -100,13 +98,14 @@
 
   if (SD) {
     if (TypedefDecl *TD = dyn_cast<TypedefDecl>(SD)) {
-      assert(TD->getUnderlyingType()->isRecordType() &&"Invalid Scope Decl!");
-      SD = TD->getUnderlyingType()->getAsRecordType()->getDecl();
+      if (const RecordType* Record = TD->getUnderlyingType()->getAsRecordType())
+        return cast<DeclContext>(Record->getDecl());
+    } else if (isa<NamespaceDecl>(SD) || isa<RecordDecl>(SD)) {
+      return cast<DeclContext>(SD);
     }
 
-    assert((isa<NamespaceDecl>(SD) || isa<RecordDecl>(SD)) &&
-           "Invalid Scope Decl!");
-    return cast<DeclContext>(SD);
+    // Fall through to produce an error: we found something that isn't
+    // a class or a namespace.
   }
 
   unsigned DiagID;

Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=61079&r1=61078&r2=61079&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Tue Dec 16 00:37:47 2008
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s 
+// RUN: clang -fsyntax-only -verify -std=c++98 %s 
 namespace A {
   struct C {
     static int cx;
@@ -72,10 +72,8 @@
   int N;
   N::x = 0; // expected-error {{expected a class or namespace}}
   { int A;           A::ax = 0; }
-  { enum A {};       A::ax = 0; }
-  { enum A { A };    A::ax = 0; }
-  { typedef int A;   A::ax = 0; }
-  { typedef int A(); A::ax = 0; }
+  { typedef int A;   A::ax = 0; } // expected-error{{expected a class or namespace}}
+  { int A(); A::ax = 0; }
   { typedef A::C A;  A::ax = 0; } // expected-error {{no member named 'ax'}}
   { typedef A::C A;  A::cx = 0; }
 }
@@ -90,3 +88,18 @@
 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
 
 void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
+
+
+namespace E {
+  int X = 5;
+  
+  namespace Nested {
+    enum E {
+      X = 0
+    };
+
+    void f() {
+      return E::X; // expected-error{{expected a class or namespace}}
+    }
+  }
+}





More information about the cfe-commits mailing list