Author: Erich Keane Date: 2023-05-18T09:07:42-07:00 New Revision: fbd8f8985e36581487371e9ff4ac7d99655b51e7
URL: https://github.com/llvm/llvm-project/commit/fbd8f8985e36581487371e9ff4ac7d99655b51e7 DIFF: https://github.com/llvm/llvm-project/commit/fbd8f8985e36581487371e9ff4ac7d99655b51e7.diff LOG: Ensure comparison of constraints creates a code synth context This is a regression from 6db007a0 that was reported in: https://github.com/llvm/llvm-project/issues/62697 The assertion was because we require a code synthesis context for the instantiation of templates, and this reproducer causes a comparison that doesn't have a parent-template causing one to exists. This patch fixes it by creating a ConstraintNormalization context. 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 2f5fb8f8d029e..25884838d632c 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -764,6 +764,15 @@ static const Expr *SubstituteConstraintExpression(Sema &S, const NamedDecl *ND, return ConstrExpr; Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false); + + Sema::InstantiatingTemplate Inst( + S, ND->getLocation(), + Sema::InstantiatingTemplate::ConstraintNormalization{}, + const_cast<NamedDecl *>(ND), SourceRange{}); + + if (Inst.isInvalid()) + return nullptr; + std::optional<Sema::CXXThisScopeRAII> ThisScope; if (auto *RD = dyn_cast<CXXRecordDecl>(ND->getDeclContext())) ThisScope.emplace(S, const_cast<CXXRecordDecl *>(RD), Qualifiers()); diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index b7c91712f8713..25b34f0644a17 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -399,3 +399,16 @@ inline void W0<T7, 0>::W1<T8>::f(const T9 &) {} } // namespace three_level } // namespace MultilevelTemplateWithPartialSpecialization + +namespace PR62697 { +template<typename> +concept c = true; + +template<typename T> +struct s { + void f() requires c<void(T)>; +}; + +template<typename T> +void s<T>::f() requires c<void(T)> { } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits