[cfe-commits] r140304 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Douglas Gregor dgregor at apple.com
Thu Sep 22 08:57:07 PDT 2011


Author: dgregor
Date: Thu Sep 22 10:57:07 2011
New Revision: 140304

URL: http://llvm.org/viewvc/llvm-project?rev=140304&view=rev
Log:
Don't allow template argument deduction to deduce a placeholder type,
ever. Fixes PR10939.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=140304&r1=140303&r2=140304&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Sep 22 10:57:07 2011
@@ -977,6 +977,10 @@
   //     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;
 

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp?rev=140304&r1=140303&r2=140304&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp Thu Sep 22 10:57:07 2011
@@ -83,4 +83,21 @@
   }
 };
 
+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>.





More information about the cfe-commits mailing list