Skip to content

Commit bfd6433

Browse files
committed
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.
1 parent a19461d commit bfd6433

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ checkDeducedTemplateArguments(ASTContext &Context,
355355
TemplateArgument Merged = checkDeducedTemplateArguments(
356356
Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()),
357357
DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound()));
358-
if (Merged.isNull())
358+
if (Merged.isNull() && !(XA->isNull() && YA->isNull()))
359359
return DeducedTemplateArgument();
360360
NewPack.push_back(Merged);
361361
}

clang/test/SemaTemplate/deduction.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,19 @@ namespace PR44890 {
581581
return w.get<0>();
582582
}
583583
}
584+
585+
namespace merge_size_only_deductions {
586+
#if __cplusplus >= 201703L
587+
// Based on a testcase by Hubert Tong.
588+
template<typename ...> struct X {};
589+
template<auto ...> struct Y {};
590+
template<typename T> struct id { using Type = T; };
591+
592+
template<typename ...T, typename T::Type ...V>
593+
int f(X<char [V] ...>, Y<V ...>, X<T ...>);
594+
595+
using size_t = __SIZE_TYPE__;
596+
int a = f(X<char [1], char [2]>(), Y<(size_t)1, (size_t)2>(), X<id<size_t>, id<size_t>>());
597+
int b = f(X<char [1], char [2]>(), Y<1, 2>(), X<id<int>, id<int>>());
598+
#endif
599+
}

0 commit comments

Comments
 (0)