[PATCH] D26893: [Sema] Fix assert on valid during template argument deduction
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 19 21:43:07 PST 2016
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26893.78649.patch
Type: text/x-patch
Size: 1257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161120/a4ac2f69/attachment.bin>
More information about the cfe-commits
mailing list