erik.pilkington created this revision. erik.pilkington added a reviewer: rsmith. erik.pilkington added a subscriber: cfe-commits.
This patch fixes an assert that fired when diagnosing a failed template argument deduction attempt. The problem is that when deducing template arguments for a template specialization, if there are insufficient template arguments, we return `Sema::TDK_TooFewArguments`, which is meant to be used with call arguments, not template arguments and therefore confuses the diagnostic handling. This patch fixes the assert by instead returning `Sema::TDK_MiscellaneousDeductionFailure`. This fixes a regression introduced in r274077, recorded by PR31043. Thanks! https://reviews.llvm.org/D26893 Files: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/deduction.cpp Index: test/SemaTemplate/deduction.cpp =================================================================== --- test/SemaTemplate/deduction.cpp +++ test/SemaTemplate/deduction.cpp @@ -273,3 +273,13 @@ } void g() { f(X<int*, nullptr>()); } } + +namespace PR31043 { +template <class... Ts> +struct tuple {}; + +template <class T> +int foo(tuple<T>); // expected-note{{candidate template ignored: failed template argument deduction}} + +int z = foo(tuple<>{}); // expected-error{{no matching function call to 'foo'}} +} Index: lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -1921,8 +1921,9 @@ // Check whether we have enough arguments. if (!hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs)) - return NumberOfArgumentsMustMatch ? Sema::TDK_TooFewArguments - : Sema::TDK_Success; + return NumberOfArgumentsMustMatch + ? Sema::TDK_MiscellaneousDeductionFailure + : Sema::TDK_Success; if (Args[ArgIdx].isPackExpansion()) { // FIXME: We follow the logic of C++0x [temp.deduct.type]p22 here,
Index: test/SemaTemplate/deduction.cpp =================================================================== --- test/SemaTemplate/deduction.cpp +++ test/SemaTemplate/deduction.cpp @@ -273,3 +273,13 @@ } void g() { f(X<int*, nullptr>()); } } + +namespace PR31043 { +template <class... Ts> +struct tuple {}; + +template <class T> +int foo(tuple<T>); // expected-note{{candidate template ignored: failed template argument deduction}} + +int z = foo(tuple<>{}); // expected-error{{no matching function call to 'foo'}} +} Index: lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -1921,8 +1921,9 @@ // Check whether we have enough arguments. if (!hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs)) - return NumberOfArgumentsMustMatch ? Sema::TDK_TooFewArguments - : Sema::TDK_Success; + return NumberOfArgumentsMustMatch + ? Sema::TDK_MiscellaneousDeductionFailure + : Sema::TDK_Success; if (Args[ArgIdx].isPackExpansion()) { // FIXME: We follow the logic of C++0x [temp.deduct.type]p22 here,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits