[cfe-commits] r92245 - in /cfe/trunk: lib/Sema/SemaLookup.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/using-decl-1.cpp

Chandler Carruth chandlerc at gmail.com
Mon Dec 28 22:17:28 PST 2009


Author: chandlerc
Date: Tue Dec 29 00:17:27 2009
New Revision: 92245

URL: http://llvm.org/viewvc/llvm-project?rev=92245&view=rev
Log:
Handle using declarations in overloaded and template functions during ADL and
address resolution. This fixes PR5751.

Also, while we're here, remove logic from ADL which mistakenly included the
definition namespaces of overloaded and/or templated functions whose name or
address is used as an argument.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/using-decl-1.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Dec 29 00:17:27 2009
@@ -1528,15 +1528,12 @@
 
     for (llvm::SmallVectorImpl<NamedDecl*>::iterator I = Functions.begin(),
            E = Functions.end(); I != E; ++I) {
-      FunctionDecl *FDecl = dyn_cast<FunctionDecl>(*I);
-      if (!FDecl)
-        FDecl = cast<FunctionTemplateDecl>(*I)->getTemplatedDecl();
+      // Look through any using declarations to find the underlying function.
+      NamedDecl *Fn = (*I)->getUnderlyingDecl();
 
-      // Add the namespace in which this function was defined. Note
-      // that, if this is a member function, we do *not* consider the
-      // enclosing namespace of its class.
-      DeclContext *Ctx = FDecl->getDeclContext();
-      CollectNamespace(AssociatedNamespaces, Ctx);
+      FunctionDecl *FDecl = dyn_cast<FunctionDecl>(Fn);
+      if (!FDecl)
+        FDecl = cast<FunctionTemplateDecl>(Fn)->getTemplatedDecl();
 
       // Add the classes and namespaces associated with the parameter
       // types and return type of this function.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Dec 29 00:17:27 2009
@@ -4465,6 +4465,9 @@
   bool FoundNonTemplateFunction = false;
   for (llvm::SmallVectorImpl<NamedDecl*>::iterator I = Fns.begin(),
          E = Fns.end(); I != E; ++I) {
+    // Look through any using declarations to find the underlying function.
+    NamedDecl *Fn = (*I)->getUnderlyingDecl();
+
     // C++ [over.over]p3:
     //   Non-member functions and static member functions match
     //   targets of type "pointer-to-function" or "reference-to-function."
@@ -4473,7 +4476,7 @@
     // Note that according to DR 247, the containing class does not matter.
 
     if (FunctionTemplateDecl *FunctionTemplate
-          = dyn_cast<FunctionTemplateDecl>(*I)) {
+          = dyn_cast<FunctionTemplateDecl>(Fn)) {
       if (CXXMethodDecl *Method
             = dyn_cast<CXXMethodDecl>(FunctionTemplate->getTemplatedDecl())) {
         // Skip non-static function templates when converting to pointer, and
@@ -4510,7 +4513,7 @@
       continue;
     }
 
-    if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(*I)) {
+    if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) {
       // Skip non-static functions when converting to pointer, and static
       // when converting to member pointer.
       if (Method->isStatic() == IsMember)
@@ -4522,7 +4525,7 @@
     } else if (IsMember)
       continue;
 
-    if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(*I)) {
+    if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(Fn)) {
       QualType ResultTy;
       if (Context.hasSameUnqualifiedType(FunctionType, FunDecl->getType()) ||
           IsNoReturnConversion(Context, FunDecl->getType(), FunctionType, 

Modified: cfe/trunk/test/SemaCXX/using-decl-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-1.cpp?rev=92245&r1=92244&r2=92245&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/using-decl-1.cpp (original)
+++ cfe/trunk/test/SemaCXX/using-decl-1.cpp Tue Dec 29 00:17:27 2009
@@ -42,3 +42,21 @@
 struct A { void f(); };
 struct B : A { };
 class C : B { using B::f; };
+
+// PR5751: Resolve overloaded functions through using decls.
+namespace O {
+  void f(int i);
+  void f(double d);
+}
+namespace P {
+  void f();
+  void g(void (*ptr)(int));
+  using O::f;
+  void test() {
+    f();
+    f(1);
+    void (*f_ptr1)(double) = f;
+    void (*f_ptr2)() = f;
+    g(f);
+  }
+}





More information about the cfe-commits mailing list