-
Notifications
You must be signed in to change notification settings - Fork 15k
[Clang] Fix a bug when checking non-dependent constraints #162969
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We check the non-dependent constraints early with empty template arguments when we build a nested requirement. Therefore we cannot assume a non-empty MLTAL within the Checker. No release note because this is a regression on trunk.
|
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesWe check the non-dependent constraints early with empty template arguments when we build a nested requirement. Therefore we cannot assume a non-empty MLTAL within the Checker. No release note because this is a regression on trunk. Full diff: https://github.com/llvm/llvm-project/pull/162969.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f4df63c1d2243..13e7960dafdcf 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -604,6 +604,10 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
return std::nullopt;
const NormalizedConstraint::OccurenceList &Used =
Constraint.mappingOccurenceList();
+ // The empty MLTAL situation should only occur when evaluating non-dependent
+ // constraints.
+ if (!MLTAL.getNumSubstitutedLevels())
+ MLTAL.addOuterTemplateArguments(TD, {}, /*Final=*/false);
SubstitutedOuterMost =
llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
unsigned Offset = 0;
@@ -623,9 +627,7 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
if (Offset < SubstitutedOuterMost.size())
SubstitutedOuterMost.erase(SubstitutedOuterMost.begin() + Offset);
- MLTAL.replaceOutermostTemplateArguments(
- const_cast<NamedDecl *>(Constraint.getConstraintDecl()),
- SubstitutedOuterMost);
+ MLTAL.replaceOutermostTemplateArguments(TD, SubstitutedOuterMost);
return std::move(MLTAL);
}
@@ -956,11 +958,18 @@ ExprResult ConstraintSatisfactionChecker::Evaluate(
? Constraint.getPackSubstitutionIndex()
: PackSubstitutionIndex;
- Sema::InstantiatingTemplate _(S, ConceptId->getBeginLoc(),
- Sema::InstantiatingTemplate::ConstraintsCheck{},
- ConceptId->getNamedConcept(),
- MLTAL.getInnermost(),
- Constraint.getSourceRange());
+ Sema::InstantiatingTemplate _(
+ S, ConceptId->getBeginLoc(),
+ Sema::InstantiatingTemplate::ConstraintsCheck{},
+ ConceptId->getNamedConcept(),
+ // We may have empty template arguments when checking non-dependent
+ // nested constraint expressions.
+ // In such cases, non-SFINAE errors would have already been diagnosed
+ // during parameter mapping substitution, so the instantiating template
+ // arguments are less useful here.
+ MLTAL.getNumSubstitutedLevels() ? MLTAL.getInnermost()
+ : ArrayRef<TemplateArgument>{},
+ Constraint.getSourceRange());
unsigned Size = Satisfaction.Details.size();
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 768af09afe9e2..a046fc47d1d18 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1404,6 +1404,18 @@ static_assert(!std::is_constructible_v<span<4>, array<int, 3>>);
}
+namespace case7 {
+
+template <class _Tp, class _Up>
+concept __same_as_impl = __is_same(_Tp, _Up);
+template <class _Tp, class _Up>
+concept same_as = __same_as_impl<_Tp, _Up>;
+template <typename>
+concept IsEntitySpec =
+ requires { requires same_as<void, void>; };
+
+}
+
}
namespace GH162125 {
|
cor3ntin
approved these changes
Oct 11, 2025
DharuniRAcharya
pushed a commit
to DharuniRAcharya/llvm-project
that referenced
this pull request
Oct 13, 2025
We check the non-dependent constraints early with empty template arguments when we build a nested requirement. Therefore we cannot assume a non-empty MLTAL within the Checker. No release note because this is a regression on trunk.
akadutta
pushed a commit
to akadutta/llvm-project
that referenced
this pull request
Oct 14, 2025
We check the non-dependent constraints early with empty template arguments when we build a nested requirement. Therefore we cannot assume a non-empty MLTAL within the Checker. No release note because this is a regression on trunk.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We check the non-dependent constraints early with empty template arguments when we build a nested requirement. Therefore we cannot assume a non-empty MLTAL within the Checker.
No release note because this is a regression on trunk.