Skip to content

Commit 1541d2d

Browse files
cor3ntinllvmbot
authored andcommitted
[Clang] SFINAE on mismatching pack length during constraint satisfaction checking (llvm#101879)
If a fold expanded constraint would expand packs of different size, it is not a valid pack expansion and it is not satisfied. This should not produce an error. Fixes llvm#99430 (cherry picked from commit da380b2)
1 parent d033ae1 commit 1541d2d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/Sema/SemaConcept.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ static ExprResult calculateConstraintSatisfaction(
531531

532532
std::optional<unsigned>
533533
EvaluateFoldExpandedConstraintSize(const CXXFoldExpr *FE) const {
534+
535+
// We should ignore errors in the presence of packs of different size.
536+
Sema::SFINAETrap Trap(S);
537+
534538
Expr *Pattern = FE->getPattern();
535539

536540
SmallVector<UnexpandedParameterPack, 2> Unexpanded;

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,33 @@ static_assert(S<int>::g<int>() == 2); // expected-error {{call to 'g' is ambiguo
275275

276276

277277
}
278+
279+
namespace GH99430 {
280+
281+
template <class _Ty1, class _Ty2>
282+
using _Synth_three_way_result = int;
283+
284+
template <class... _Types>
285+
class tuple;
286+
287+
template <int _Index>
288+
struct tuple_element;
289+
290+
template <class, int...>
291+
struct _Three_way_comparison_result_with_tuple_like {
292+
using type = int;
293+
};
294+
295+
template <class... _TTypes, int... _Indices>
296+
requires(requires {
297+
typename _Synth_three_way_result<_TTypes, tuple_element<_Indices>>;
298+
} && ...)
299+
300+
struct _Three_way_comparison_result_with_tuple_like<tuple<_TTypes...>, _Indices...>{
301+
using type = long;
302+
};
303+
304+
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<int>, 0, 1>::type, int));
305+
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<int>, 0>::type, long));
306+
307+
}

0 commit comments

Comments
 (0)