[cfe-commits] r164263 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp

Eli Friedman eli.friedman at gmail.com
Wed Sep 19 16:27:05 PDT 2012


Author: efriedma
Date: Wed Sep 19 18:27:04 2012
New Revision: 164263

URL: http://llvm.org/viewvc/llvm-project?rev=164263&view=rev
Log:
Fix function template partial ordering rules for static vs. non-static
functions.


Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=164263&r1=164262&r2=164263&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Sep 19 18:27:04 2012
@@ -3711,7 +3711,7 @@
     IsNonStatic1 = Method1 && !Method1->isStatic();
     IsNonStatic2 = Method2 && !Method2->isStatic();
 
-    // C++0x [temp.func.order]p3:
+    // C++11 [temp.func.order]p3:
     //   [...] If only one of the function templates is a non-static
     //   member, that function template is considered to have a new
     //   first parameter inserted in its function parameter list. The
@@ -3719,21 +3719,24 @@
     //   the cv-qualifiers of the function template (if any) and A is
     //   the class of which the function template is a member.
     //
+    // Note that we interpret this to mean "if one of the function
+    // templates is a non-static member and the other is a non-member";
+    // otherwise, the ordering rules for static functions against non-static
+    // functions don't make any sense.
+    //
     // C++98/03 doesn't have this provision, so instead we drop the
-    // first argument of the free function or static member, which
-    // seems to match existing practice.
+    // first argument of the free function, which seems to match
+    // existing practice.
     SmallVector<QualType, 4> Args1;
-    unsigned Skip1 = !S.getLangOpts().CPlusPlus0x &&
-      IsNonStatic2 && !IsNonStatic1;
-    if (S.getLangOpts().CPlusPlus0x && IsNonStatic1 && !IsNonStatic2)
+    unsigned Skip1 = !S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !Method1;
+    if (S.getLangOpts().CPlusPlus0x && IsNonStatic1 && !Method2)
       MaybeAddImplicitObjectParameterType(S.Context, Method1, Args1);
     Args1.insert(Args1.end(),
                  Proto1->arg_type_begin() + Skip1, Proto1->arg_type_end());
 
     SmallVector<QualType, 4> Args2;
-    Skip2 = !S.getLangOpts().CPlusPlus0x &&
-      IsNonStatic1 && !IsNonStatic2;
-    if (S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !IsNonStatic1)
+    Skip2 = !S.getLangOpts().CPlusPlus0x && IsNonStatic1 && !Method2;
+    if (S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !Method1)
       MaybeAddImplicitObjectParameterType(S.Context, Method2, Args2);
     Args2.insert(Args2.end(),
                  Proto2->arg_type_begin() + Skip2, Proto2->arg_type_end());

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp?rev=164263&r1=164262&r2=164263&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3-0x.cpp Wed Sep 19 18:27:04 2012
@@ -15,3 +15,15 @@
     int &ir = b * a;
   }
 }
+
+namespace OrderWithStaticMember {
+  struct A {
+    template<class T> int g(T**, int=0) { return 0; }
+    template<class T> static int g(T*) { return 1; }
+  };
+  void f() {
+    A a;
+    int **p;
+    a.g(p);
+  }
+}

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp?rev=164263&r1=164262&r2=164263&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p3.cpp Wed Sep 19 18:27:04 2012
@@ -14,3 +14,15 @@
     float& ir = (xi == xf);
   }
 }
+
+namespace OrderWithStaticMember {
+  struct A {
+    template<class T> int g(T**, int=0) { return 0; }
+    template<class T> static int g(T*) { return 1; }
+  };
+  void f() {
+    A a;
+    int **p;
+    a.g(p);
+  }
+}





More information about the cfe-commits mailing list