diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-04-04 05:10:53 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-04-04 05:10:53 +0000 |
commit | d280389b42bb55cd8969eae181dc3ff9f05e9aaf (patch) | |
tree | e75b6665dfd1e830eca7bd514747fe26092f262d /lib/Sema/SemaTemplateDeduction.cpp | |
parent | a9b55a499a8b5ae0c4b373f751ef62af74ec494e (diff) |
When performing template argument deduction for an initializer list,
be sure to perform the argument type adjustments in
[temp.deduct.call]p2, e.g., array decay.
And, when performing these deductions in the context of 'auto', make
sure that we're deducing the P' in std::initializer_list<P'> rather
than the whole initializer list.
Together, this makes code like
for( auto s : {"Deferred", "New", "Open", "Review"}) { }
work properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153998 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index bc6138d559..b448633381 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -2935,8 +2935,12 @@ DeduceTemplateArgumentByListElement(Sema &S, } // For all other cases, just match by type. + QualType ArgType = Arg->getType(); + if (AdjustFunctionParmAndArgTypesForDeduction(S, TemplateParams, ParamType, + ArgType, Arg, TDF)) + return Sema::TDK_FailedOverloadResolution; return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, ParamType, - Arg->getType(), Info, Deduced, TDF); + ArgType, Info, Deduced, TDF); } /// \brief Perform template argument deduction from a function call @@ -3494,22 +3498,24 @@ Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *&Init, Deduced.resize(1); QualType InitType = Init->getType(); unsigned TDF = 0; - if (AdjustFunctionParmAndArgTypesForDeduction(*this, &TemplateParams, - FuncParam, InitType, Init, - TDF)) - return DAR_Failed; TemplateDeductionInfo Info(Context, Loc); InitListExpr * InitList = dyn_cast<InitListExpr>(Init); if (InitList) { for (unsigned i = 0, e = InitList->getNumInits(); i < e; ++i) { - if (DeduceTemplateArgumentsByTypeMatch(*this, &TemplateParams, FuncParam, - InitList->getInit(i)->getType(), - Info, Deduced, TDF)) + if (DeduceTemplateArgumentByListElement(*this, &TemplateParams, + TemplArg, + InitList->getInit(i), + Info, Deduced, TDF)) return DAR_Failed; } } else { + if (AdjustFunctionParmAndArgTypesForDeduction(*this, &TemplateParams, + FuncParam, InitType, Init, + TDF)) + return DAR_Failed; + if (DeduceTemplateArgumentsByTypeMatch(*this, &TemplateParams, FuncParam, InitType, Info, Deduced, TDF)) return DAR_Failed; |