Author: Younan Zhang Date: 2024-11-04T22:35:32+08:00 New Revision: 227afac307fac0d4c8ac2a3709df415e34629883
URL: https://github.com/llvm/llvm-project/commit/227afac307fac0d4c8ac2a3709df415e34629883 DIFF: https://github.com/llvm/llvm-project/commit/227afac307fac0d4c8ac2a3709df415e34629883.diff LOG: [Clang] Consider outer instantiation scopes for constraint normalization (#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 https://github.com/llvm/llvm-project/issues/114685 Added: Modified: clang/lib/Sema/SemaConcept.cpp clang/test/SemaTemplate/concepts-out-of-line-def.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index e36ee062213716..bc988001ea7e46 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -975,7 +975,7 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( std::optional<LocalInstantiationScope> ScopeForParameters; if (const NamedDecl *ND = DeclInfo.getDecl(); ND && ND->isFunctionOrFunctionTemplate()) { - ScopeForParameters.emplace(S); + ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true); const FunctionDecl *FD = ND->getAsFunction(); for (auto *PVD : FD->parameters()) { if (!PVD->isParameterPack()) { diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index fe8f74928fc370..dd518d283c83c8 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -702,3 +702,19 @@ class TTP; C v; } // namespace GH93099 + +namespace GH114685 { + +template <typename T> struct ptr { + template <typename U> + friend ptr<U> make_item(auto &&args) + requires(sizeof(args) > 1); +}; + +template <typename U> +ptr<U> make_item(auto &&args) + requires(sizeof(args) > 1) {} + +ptr<char> p; + +} // namespace GH114685 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits