From da380b26e4748ade5a8dba85b7df5e1c4eded8bc Mon Sep 17 00:00:00 2001 From: cor3ntin Date: Mon, 5 Aug 2024 14:22:07 +0200 Subject: [PATCH] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (#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 #99430 --- clang/lib/Sema/SemaConcept.cpp | 4 ++++ clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 30 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 75ccefa2a487e..d4c9d044985e3 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -532,6 +532,10 @@ static ExprResult calculateConstraintSatisfaction( std::optional EvaluateFoldExpandedConstraintSize(const CXXFoldExpr *FE) const { + + // We should ignore errors in the presence of packs of different size. + Sema::SFINAETrap Trap(S); + Expr *Pattern = FE->getPattern(); SmallVector Unexpanded; diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp index 1e0bc7bcfb4e7..0674135aac483 100644 --- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp +++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp @@ -275,3 +275,33 @@ static_assert(S::g() == 2); // expected-error {{call to 'g' is ambiguo } + +namespace GH99430 { + +template +using _Synth_three_way_result = int; + +template +class tuple; + +template +struct tuple_element; + +template +struct _Three_way_comparison_result_with_tuple_like { + using type = int; +}; + +template + requires(requires { + typename _Synth_three_way_result<_TTypes, tuple_element<_Indices>>; + } && ...) + +struct _Three_way_comparison_result_with_tuple_like, _Indices...>{ + using type = long; +}; + +static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like, 0, 1>::type, int)); +static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like, 0>::type, long)); + +}