diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5732,7 +5732,8 @@ Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack, TypeConstraintConcept, CanonArgs, true); // Find the insert position again. - AutoTypes.FindNodeOrInsertPos(ID, InsertPos); + if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) + return QualType(AT, 0); } } else { Canon = DeducedType.getCanonicalType(); diff --git a/clang/test/SemaCXX/sugared-auto.cpp b/clang/test/SemaCXX/sugared-auto.cpp --- a/clang/test/SemaCXX/sugared-auto.cpp +++ b/clang/test/SemaCXX/sugared-auto.cpp @@ -41,3 +41,33 @@ N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}} } // namespace function_basic + +namespace issue57142 { + +// Should not crash here +// Reported by https://github.com/llvm/llvm-project/issues/57142 + + +// Only crashes if `tuple` is defined outside of the buggy namespace +namespace outer { + template class tuple; +} // namespace outer + +namespace { +struct false_type { + static const bool value = false; +}; + +template class, typename> +struct IsTemplateOf : false_type {}; + +template class ATemplate> +concept InitFrom = IsTemplateOf::value; + + +static void buggy_func( + const InitFrom auto& C // crashed here in #57142 +); +} // namespace + +} // namespace issue57142