mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-29 08:36:07 +00:00

This is yet another one-line patch to fix crashes on constraint substitution. ```cpp template <class, class> struct formatter; template <class, class> struct basic_format_context {}; template <typename CharType> concept has_format_function = format(basic_format_context<CharType, CharType>()); template <typename ValueType, typename CharType> requires has_format_function<CharType> struct formatter<ValueType, CharType> { template <typename OutputIt> CharType format(basic_format_context<OutputIt, CharType>); }; ``` In this case, we would build up a `RecoveryExpr` for a call within a constraint expression due to the absence of viable functions. The heuristic algorithm attempted to find such a function inside of a ClassTemplatePartialSpecialization, from which we started to substitute its requires-expression, and it succeeded with a FunctionTemplate such that 1) It has only one parameter, which is dependent. 2) The only one parameter depends on two template parameters. They are, in canonical form, `<template-parameter-1-0>` and `<template-parameter-0-1>` respectively. Before we emit an error, we still want to recover the most viable functions. This goes downhill to deducing template parameters against its arguments, where we would collect the argument type with the same depth as the parameter type into a Deduced set. The size of the set is presumed to be that of function template parameters, which is 1 in this case. However, since we haven't yet properly set the template depth before the dance, we'll end up putting the type for `<template-parameter-0-1>` to the second position of Deduced set, which is unfortunately an access violation! The bug seems to appear since clang 12.0. This fixes [the case](https://github.com/llvm/llvm-project/issues/58548#issuecomment-1287935336).