diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index f04cc454cdb7c..fb4d0b4582684 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -2408,11 +2408,16 @@ const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints( if (CacheEntry == NormalizationCache.end()) { auto *Normalized = NormalizedConstraint::fromAssociatedConstraints( *this, ND, AssociatedConstraints); + if (!Normalized) { + NormalizationCache.try_emplace(ConstrainedDeclOrNestedReq, nullptr); + return nullptr; + } + // substitute() can invalidate iterators of NormalizationCache. + bool Failed = SubstituteParameterMappings(*this).substitute(*Normalized); CacheEntry = NormalizationCache.try_emplace(ConstrainedDeclOrNestedReq, Normalized) .first; - if (!Normalized || - SubstituteParameterMappings(*this).substitute(*Normalized)) + if (Failed) return nullptr; } return CacheEntry->second; diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index becf5467a1b61..c90af41a09468 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1632,3 +1632,29 @@ void fn3() { } } + +namespace GH165238 { + +namespace std { +template +concept output_iterator = requires(_Tp __t) { __t; }; +template struct basic_format_context { + static_assert(output_iterator<_Out, int>); + using char_type = _Out; +}; +template class basic_format_parse_context; +template > +concept __parsable_with = requires(_Formatter __f) { __f; }; +template > +concept __formattable_impl = __parsable_with<_Tp, _Context, _Context>; +template +concept formattable = __formattable_impl<_Tp, _CharT>; +} // namespace std +struct { + void operator()(std::formattable auto); +} call; +void foo() { call(""); } + +}