]> granicus.if.org Git - clang/commitdiff
Don't allow template argument deduction to deduce a placeholder type,
authorDouglas Gregor <dgregor@apple.com>
Thu, 22 Sep 2011 15:57:07 +0000 (15:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 22 Sep 2011 15:57:07 +0000 (15:57 +0000)
ever. Fixes PR10939.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140304 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

index 762e51a32c8026a46cc9482ed08fe9ca4ee39318..add8e10831ba3d0e6dde7ef0725dc257844bd835 100644 (file)
@@ -977,6 +977,10 @@ DeduceTemplateArguments(Sema &S,
   //     cv-list T
   if (const TemplateTypeParmType *TemplateTypeParm
         = Param->getAs<TemplateTypeParmType>()) {
+    // Just skip any attempts to deduce from a placeholder type.
+    if (Arg->isPlaceholderType())
+      return Sema::TDK_Success;
+    
     unsigned Index = TemplateTypeParm->getIndex();
     bool RecanonicalizeArg = false;
 
index 25ce99fc10ef5276bc9a9e87a66e9053b8e4b077..c150a6123cd5761c2de0a6356a66d85a3d18b6b7 100644 (file)
@@ -83,4 +83,21 @@ struct S {
   }
 };
 
+namespace PR10939 {
+  struct X {
+    int method(int);
+    int method(float); 
+  };
+
+  template<typename T> T g(T);
+
+  void f(X *x) {
+    auto value = x->method; // expected-error{{variable 'value' with type 'auto' has incompatible initializer of type '<bound member function type>'}}
+    if (value) { }
+
+    auto funcptr = &g<int>;
+    int (*funcptr2)(int) = funcptr;
+  }
+}
+
 // TODO: if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>.