Skip to content

Commit 227afac

Browse files
authored
[Clang] Consider outer instantiation scopes for constraint normalization (llvm#114749)
We need to compare constraint expressions when instantiating a friend declaration that is lexically defined within a class template. Since the evaluation is deferred, the expression might refer to untransformed function parameters such that the substitution needs the mapping of instantiation. These mappings are maintained by the function declaration instantiation, so we need to establish a "transparent" LocalInstantiationScope before substituting into the constraint. No release note as this fixes a regression in 19. Fixes llvm#114685
1 parent 2f1a0df commit 227afac

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaConcept.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
975975
std::optional<LocalInstantiationScope> ScopeForParameters;
976976
if (const NamedDecl *ND = DeclInfo.getDecl();
977977
ND && ND->isFunctionOrFunctionTemplate()) {
978-
ScopeForParameters.emplace(S);
978+
ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true);
979979
const FunctionDecl *FD = ND->getAsFunction();
980980
for (auto *PVD : FD->parameters()) {
981981
if (!PVD->isParameterPack()) {

clang/test/SemaTemplate/concepts-out-of-line-def.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,19 @@ class TTP;
702702
C v;
703703

704704
} // namespace GH93099
705+
706+
namespace GH114685 {
707+
708+
template <typename T> struct ptr {
709+
template <typename U>
710+
friend ptr<U> make_item(auto &&args)
711+
requires(sizeof(args) > 1);
712+
};
713+
714+
template <typename U>
715+
ptr<U> make_item(auto &&args)
716+
requires(sizeof(args) > 1) {}
717+
718+
ptr<char> p;
719+
720+
} // namespace GH114685

0 commit comments

Comments
 (0)