Skip to content

Commit a218508

Browse files
committed
[Clang] Consider outer instantiation scopes for constraint normalization
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.
1 parent 88823d0 commit a218508

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 0 deletions
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)