[clang] bfd6433 - Fix merging of two arity-only pack deductions.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 14 10:02:32 PDT 2020
Author: Richard Smith
Date: 2020-07-14T10:02:07-07:00
New Revision: bfd643353e6b7ca7b89c0f983ff6a24c36aed276
URL: https://github.com/llvm/llvm-project/commit/bfd643353e6b7ca7b89c0f983ff6a24c36aed276
DIFF: https://github.com/llvm/llvm-project/commit/bfd643353e6b7ca7b89c0f983ff6a24c36aed276.diff
LOG: Fix merging of two arity-only pack deductions.
If we deduced the arity of a pack in two different ways, but didn't
deduce an element of the pack in either of those deductions, we'd merge
that element to produce a null template argument, which we'd incorrectly
interpret as the merge having failed.
Testcase based on one supplied by Hubert Tong.
Added:
Modified:
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/deduction.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index f3641afbbf8a..5392be57a3aa 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -355,7 +355,7 @@ checkDeducedTemplateArguments(ASTContext &Context,
TemplateArgument Merged = checkDeducedTemplateArguments(
Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()),
DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound()));
- if (Merged.isNull())
+ if (Merged.isNull() && !(XA->isNull() && YA->isNull()))
return DeducedTemplateArgument();
NewPack.push_back(Merged);
}
diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index 5218543ab8a4..a068bcaea048 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -581,3 +581,19 @@ namespace PR44890 {
return w.get<0>();
}
}
+
+namespace merge_size_only_deductions {
+#if __cplusplus >= 201703L
+ // Based on a testcase by Hubert Tong.
+ template<typename ...> struct X {};
+ template<auto ...> struct Y {};
+ template<typename T> struct id { using Type = T; };
+
+ template<typename ...T, typename T::Type ...V>
+ int f(X<char [V] ...>, Y<V ...>, X<T ...>);
+
+ using size_t = __SIZE_TYPE__;
+ int a = f(X<char [1], char [2]>(), Y<(size_t)1, (size_t)2>(), X<id<size_t>, id<size_t>>());
+ int b = f(X<char [1], char [2]>(), Y<1, 2>(), X<id<int>, id<int>>());
+#endif
+}
More information about the cfe-commits
mailing list