Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] SFINAE on mismatching pack length during constraint satisfaction checking #101879

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Aug 4, 2024

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

…ion checking

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
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/101879.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaConcept.cpp (+4)
  • (modified) clang/test/SemaCXX/cxx2c-fold-exprs.cpp (+30)
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9e16b67284be4..c34d32002b5ad 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -531,6 +531,10 @@ static ExprResult calculateConstraintSatisfaction(
 
     std::optional<unsigned>
     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<UnexpandedParameterPack, 2> 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<int>::g<int>() == 2); // expected-error {{call to 'g' is ambiguo
 
 
 }
+
+namespace GH99430 {
+
+template <class _Ty1, class _Ty2>
+using _Synth_three_way_result = int;
+
+template <class... _Types>
+class tuple;
+
+template <int _Index>
+struct tuple_element;
+
+template <class, int...>
+struct _Three_way_comparison_result_with_tuple_like {
+  using type = int;
+};
+
+template <class... _TTypes, int... _Indices>
+  requires(requires {
+    typename _Synth_three_way_result<_TTypes, tuple_element<_Indices>>;
+  } && ...)
+
+struct _Three_way_comparison_result_with_tuple_like<tuple<_TTypes...>, _Indices...>{
+    using type = long;
+};
+
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<int>, 0, 1>::type, int));
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<int>, 0>::type, long));
+
+}

@cor3ntin
Copy link
Contributor Author

cor3ntin commented Aug 4, 2024

The intent is for this to be backported to 19 (therefore no changelog)

This was a fairly easy fix thanks to @Endilll reduction! Very much appreciated :)

Copy link
Contributor

@Endilll Endilll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Endilll
Copy link
Contributor

Endilll commented Aug 4, 2024

The intent is for this to be backported to 19 (therefore no changelog)

Yes, this is very important to backport.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This should be backported, thank you for the quick fix!

@cor3ntin cor3ntin merged commit da380b2 into llvm:main Aug 5, 2024
10 checks passed
@cor3ntin cor3ntin added this to the LLVM 19.X Release milestone Aug 5, 2024
@cor3ntin
Copy link
Contributor Author

cor3ntin commented Aug 5, 2024

/cherry-pick da380b2

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 5, 2024
…ion 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)
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2024

/pull-request #101967

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 10, 2024
…ion 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)
CaseyCarter added a commit to CaseyCarter/STL that referenced this pull request Aug 14, 2024
**DO NOT MERGE** this has been fixed for rc3 by llvm/llvm-project#101879.
CaseyCarter added a commit to CaseyCarter/STL that referenced this pull request Aug 24, 2024
**DO NOT MERGE** this has been fixed for rc3 by llvm/llvm-project#101879.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

[clang] clang-cl main branch refuses to compile MSVC's tuple template with /std:c++latest
4 participants