Skip to content

Commit beec840

Browse files
authored
[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
1 parent 5bac67d commit beec840

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ Bug Fixes in This Version
808808
nested scopes. (#GH147495)
809809
- Fixed a failed assertion with an operator call expression which comes from a
810810
macro expansion when performing analysis for nullability attributes. (#GH138371)
811+
- Fixed a concept equivalent checking crash due to untransformed constraint expressions. (#GH146614)
811812

812813
Bug Fixes to Compiler Builtins
813814
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaConcept.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,12 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
925925
ND && ND->isFunctionOrFunctionTemplate()) {
926926
ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true);
927927
const FunctionDecl *FD = ND->getAsFunction();
928+
if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate();
929+
Template && Template->getInstantiatedFromMemberTemplate())
930+
FD = Template->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
928931
for (auto *PVD : FD->parameters()) {
932+
if (ScopeForParameters->getInstantiationOfIfExists(PVD))
933+
continue;
929934
if (!PVD->isParameterPack()) {
930935
ScopeForParameters->InstantiatedLocal(PVD, PVD);
931936
continue;

clang/test/SemaTemplate/concepts-using-decl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,24 @@ void func() {
176176
f.foo<10, 10>(); // expected-error {{no matching member function for call to 'foo'}}
177177
}
178178
} // namespace heads_without_concepts.
179+
180+
namespace GH146614 {
181+
182+
template <typename T>
183+
struct base {
184+
template <typename A>
185+
void foo(A x)
186+
requires (requires{x;})
187+
{}
188+
};
189+
190+
191+
struct child : base<int> {
192+
using base<int>::foo;
193+
template <typename A>
194+
void foo(A x)
195+
requires (false)
196+
{}
197+
};
198+
199+
}

0 commit comments

Comments
 (0)