aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYounan Zhang <zyn7109@gmail.com>2025-07-18 15:23:32 +0800
committerGitHub <noreply@github.com>2025-07-18 15:23:32 +0800
commitbeec840822867079b829f35cbd4b360aa8971438 (patch)
treecd895b549cf3e4171e8eee3921093a45301cb5d3
parent5bac67d9213da8afa0e35199395774ca3c7daa39 (diff)
downloadllvm-beec840822867079b829f35cbd4b360aa8971438.zip
llvm-beec840822867079b829f35cbd4b360aa8971438.tar.gz
llvm-beec840822867079b829f35cbd4b360aa8971438.tar.bz2
[Clang] Ensure correct parameters are in the scope for constraint equivalence checking (#149264)
This is another case where untransformed constraint expressions led to inconsistent transforms. We did fix some of those issues by looking at parent scopes, however the parent instantiation scope is not always available because we could also reach here after the parents get instantiated. Fixes #146614
-rw-r--r--clang/docs/ReleaseNotes.rst1
-rw-r--r--clang/lib/Sema/SemaConcept.cpp5
-rw-r--r--clang/test/SemaTemplate/concepts-using-decl.cpp21
3 files changed, 27 insertions, 0 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fcd3887..6f55d14 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -808,6 +808,7 @@ Bug Fixes in This Version
nested scopes. (#GH147495)
- Fixed a failed assertion with an operator call expression which comes from a
macro expansion when performing analysis for nullability attributes. (#GH138371)
+- Fixed a concept equivalent checking crash due to untransformed constraint expressions. (#GH146614)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 834417f..5205ca0b 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -925,7 +925,12 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
ND && ND->isFunctionOrFunctionTemplate()) {
ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true);
const FunctionDecl *FD = ND->getAsFunction();
+ if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate();
+ Template && Template->getInstantiatedFromMemberTemplate())
+ FD = Template->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
for (auto *PVD : FD->parameters()) {
+ if (ScopeForParameters->getInstantiationOfIfExists(PVD))
+ continue;
if (!PVD->isParameterPack()) {
ScopeForParameters->InstantiatedLocal(PVD, PVD);
continue;
diff --git a/clang/test/SemaTemplate/concepts-using-decl.cpp b/clang/test/SemaTemplate/concepts-using-decl.cpp
index fca69de..41f7b6d 100644
--- a/clang/test/SemaTemplate/concepts-using-decl.cpp
+++ b/clang/test/SemaTemplate/concepts-using-decl.cpp
@@ -176,3 +176,24 @@ void func() {
f.foo<10, 10>(); // expected-error {{no matching member function for call to 'foo'}}
}
} // namespace heads_without_concepts.
+
+namespace GH146614 {
+
+template <typename T>
+struct base {
+ template <typename A>
+ void foo(A x)
+ requires (requires{x;})
+ {}
+};
+
+
+struct child : base<int> {
+ using base<int>::foo;
+ template <typename A>
+ void foo(A x)
+ requires (false)
+ {}
+};
+
+}