[cfe-commits] r102695 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp

Douglas Gregor dgregor at apple.com
Fri Apr 30 00:08:38 PDT 2010


Author: dgregor
Date: Fri Apr 30 02:08:38 2010
New Revision: 102695

URL: http://llvm.org/viewvc/llvm-project?rev=102695&view=rev
Log:
Fix ADL for types declared in transparent decls, from Alp Toker!

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=102695&r1=102694&r2=102695&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Apr 30 02:08:38 2010
@@ -1386,10 +1386,18 @@
                           Sema::AssociatedNamespaceSet &AssociatedNamespaces,
                                   Sema::AssociatedClassSet &AssociatedClasses);
 
-static void CollectNamespace(Sema::AssociatedNamespaceSet &Namespaces,
-                             DeclContext *Ctx) {
+static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces,
+                                      DeclContext *Ctx) {
+  // Add the associated namespace for this class.
+
+  // We don't use DeclContext::getEnclosingNamespaceContext() as this may
+  // be a locally scoped record.
+
+  while (Ctx->isRecord() || Ctx->isTransparentContext())
+    Ctx = Ctx->getParent();
+
   if (Ctx->isFileContext())
-    Namespaces.insert(Ctx);
+    Namespaces.insert(Ctx->getPrimaryContext());
 }
 
 // \brief Add the associated classes and namespaces for argument-dependent
@@ -1425,9 +1433,7 @@
         if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
           AssociatedClasses.insert(EnclosingClass);
         // Add the associated namespace for this class.
-        while (Ctx->isRecord())
-          Ctx = Ctx->getParent();
-        CollectNamespace(AssociatedNamespaces, Ctx);
+        CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
       }
       break;
     }
@@ -1471,9 +1477,7 @@
   if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
     AssociatedClasses.insert(EnclosingClass);
   // Add the associated namespace for this class.
-  while (Ctx->isRecord())
-    Ctx = Ctx->getParent();
-  CollectNamespace(AssociatedNamespaces, Ctx);
+  CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
 
   // Add the class itself. If we've already seen this class, we don't
   // need to visit base classes.
@@ -1495,9 +1499,7 @@
     if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
       AssociatedClasses.insert(EnclosingClass);
     // Add the associated namespace for this class.
-    while (Ctx->isRecord())
-      Ctx = Ctx->getParent();
-    CollectNamespace(AssociatedNamespaces, Ctx);
+    CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
 
     const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
     for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
@@ -1538,9 +1540,7 @@
       if (AssociatedClasses.insert(BaseDecl)) {
         // Find the associated namespace for this base class.
         DeclContext *BaseCtx = BaseDecl->getDeclContext();
-        while (BaseCtx->isRecord())
-          BaseCtx = BaseCtx->getParent();
-        CollectNamespace(AssociatedNamespaces, BaseCtx);
+        CollectEnclosingNamespace(AssociatedNamespaces, BaseCtx);
 
         // Make sure we visit the bases of this base class.
         if (BaseDecl->bases_begin() != BaseDecl->bases_end())
@@ -1615,9 +1615,7 @@
       AssociatedClasses.insert(EnclosingClass);
 
     // Add the associated namespace for this class.
-    while (Ctx->isRecord())
-      Ctx = Ctx->getParent();
-    CollectNamespace(AssociatedNamespaces, Ctx);
+    CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
 
     return;
   }

Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp?rev=102695&r1=102694&r2=102695&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp Fri Apr 30 02:08:38 2010
@@ -71,3 +71,18 @@
   }
 }
 
+extern "C" {
+  struct L { };
+}
+
+void h(L); // expected-note{{candidate function}}
+
+namespace P {
+  void h(L); // expected-note{{candidate function}}
+  void test_transparent_context_adl(L l) {
+    {
+      h(l); // expected-error {{call to 'h' is ambiguous}}
+    }
+  }
+}
+





More information about the cfe-commits mailing list