From: Douglas Gregor Date: Thu, 22 Sep 2011 15:57:07 +0000 (+0000) Subject: Don't allow template argument deduction to deduce a placeholder type, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af130823cbac5c02f7fe57a5733ee511f5a3ac98;p=clang Don't allow template argument deduction to deduce a placeholder type, ever. Fixes PR10939. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140304 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 762e51a32c..add8e10831 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -977,6 +977,10 @@ DeduceTemplateArguments(Sema &S, // cv-list T if (const TemplateTypeParmType *TemplateTypeParm = Param->getAs()) { + // Just skip any attempts to deduce from a placeholder type. + if (Arg->isPlaceholderType()) + return Sema::TDK_Success; + unsigned Index = TemplateTypeParm->getIndex(); bool RecanonicalizeArg = false; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp index 25ce99fc10..c150a6123c 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp @@ -83,4 +83,21 @@ struct S { } }; +namespace PR10939 { + struct X { + int method(int); + int method(float); + }; + + template T g(T); + + void f(X *x) { + auto value = x->method; // expected-error{{variable 'value' with type 'auto' has incompatible initializer of type ''}} + if (value) { } + + auto funcptr = &g; + int (*funcptr2)(int) = funcptr; + } +} + // TODO: if the initializer is a braced-init-list, deduce auto as std::initializer_list.